[英]Bootstrap Tooltip - How can I access “this”
I have created a function to show bootstrap tooltips based on the id of the link the user is hovering over. 我创建了一个函数,用于根据用户悬停的链接的ID显示引导工具提示。
Alerting this.id is blank inside the title function - do I need to pass this through and if so how? 提醒this.id在标题函数内为空白-我需要通过它吗? (this) doesn't work and I've tried a few other methods to no avail.
(this)不起作用,我尝试了其他一些方法也无济于事。 Thank you!
谢谢!
$(document).ready(function(){
$('.tooltiplink').tooltip({
html: true,
title: function() {
return $('#' + this.id).html();
}
});
});
Use $(this)
. 使用
$(this)
。 There is no need for using $('#' + this.id)
. 无需使用
$('#' + this.id)
。 $(this)
is already the element you're looking for. $(this)
已经是您要查找的元素。
$(document).ready(function(){
$('.tooltiplink').tooltip({
html: true,
title: function() {
return $(this).html();
}
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.