You have to execute the $().qtip();
(您必须执行$()。qtip();)
on every element you dynamically add after they've been added. (在添加完每个元素后,对它们进行动态添加。)
At the moment, you add the qTips right after the page is ready, then add the new elements and then nothing.
(此刻,您可以在页面准备好后立即添加qTips,然后添加新元素,然后再添加任何内容。)
I haven't tested this, might need tweaking, but try this code, this tries to add the tooltip to the dynamically added username and email input fields:
(我尚未对此进行测试,可能需要进行调整,但是请尝试以下代码,这会尝试将工具提示添加到动态添加的用户名和电子邮件输入字段中:)
$(document).ready( function () {
$('.hasTooltip').each(function() {
qTipAdd(this);
});
show_registration_form(); // add html form with elements from my custom js function
});
function show_registration_form() {
$(".content-area").append('<form action="" method="POST"></form>');
var form2Html = [
'<input type="text" value="" name="username" id="username">',
'<input type="email" value="" name="email" id="email">',
// ... standard form content
].join('');
$(".content-area form").append(form2Html);
qTipAdd('#username');
qTipAdd('#email');
}
function qTipAdd(element) {
$(element).qtip({
content: {
text: $(this).next('div').html()
},
position: {
my: 'bottom center',
at: 'top center',
target: $(this)
},
show: {
event: 'click mouseenter',
solo: true,
effect: function(offset) {
$(this).fadeIn(100);
}
},
hide: {
fixed: true,
delay: 300
}
});
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…