我正在使用类型化库 ( https://github.com/mattboldt/typed.js/ ) 并想在字符串中放置一个链接。只需在字符串中输入 html 即可破坏它。
这是我正在尝试做的事情,
$(function(){
$(".element").typed({
strings: ["this is where text is and i'd like one of the words to be a link"],
typeSpeed: 0
});
});
任何事情都会有所帮助。谢谢。
最佳答案
由于该插件一次接受一个字母,您将无法添加链接,但您可以将其推送到末尾:
$(function(){
$(".element").typed({
strings: ["this is where text is and i'd like one of the words to be a link"],
typeSpeed: 0,
callback: function(){
addLink($(".element"), "i'd", "http://www.google.com"); // searches for "i'd" and adds link :)
}
});
});
function addLink(el, word, link) {
var rgxp = new RegExp("\\b"+word+"\\b", "gi");
var repl = '<a href="'+link+'">' + word + '</a>';
el.html(el.html().replace(rgxp, repl));
}
关于javascript - 使用类型化插件的 jQuery 文本字符串中的 html 链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26530417/