Javascript 使用类型化插件的jQuery文本字符串中的html链接
我正在使用类型库()并希望在字符串中添加链接。只需在字符串中输入html即可将其打断 这就是我想做的Javascript 使用类型化插件的jQuery文本字符串中的html链接,javascript,jquery,Javascript,Jquery,我正在使用类型库()并希望在字符串中添加链接。只需在字符串中输入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
});
});
什么都可以。谢谢 由于插件一次只需要一个字母,您将无法添加链接,但您可以在最后推送它:
$(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));
}
$(函数(){
$(“.element”)。已键入({
字符串:[“这是文本所在的位置,我希望其中一个单词成为链接”],
打字速度:0,
回调:函数(){
addLink($(“.element”),“我愿意,”http://www.google.com“”;//搜索“i'd”并添加链接:)
}
});
});
函数addLink(el、word、link){
var rgxp=new RegExp(“\\b”+word+”\\b,“gi”);
var repl='';
html(el.html().replace(rgxp,repl));
}
Jamie,我查看了文档,没有提到自定义html集成。您可以在他们的Github repo上打开一个问题,以便将来实施 另一方面,你可以认为这是我准备好的。它仍然需要一些改进,但这是另一种方法
(function typeIt() {
var humanize = Math.round(Math.random() * (200 - 30)) + 30;
timeOut = setTimeout(function() {
char++;
var type = txt.substring(0, char);
$el.html(type + '|');
typeIt();
if (char == txtLen) {
$el.html($el.html().slice(0, -1)); // remove the '|'
clearTimeout(timeOut);
}
}, humanize);
}());