我在 HTML 内容中使用 tooltipster,需要在 HTML 内容中 Hook 元素的点击。我的代码如下所示:
$('.groups-tooltip').tooltipster({
contentCloning: true,
trigger: 'custom',
interactive: true,
contentAsHTML: true,
triggerOpen: {
mouseenter: true
},
triggerClose: {
mouseleave: true
},
functionReady: function(instance, helper){
$(".tooltip-template-div").hide();
$('.tooltip-template-span').on("click", function(){
console.log("Clicked!");
});
instance.content($('#tooltip-template').html());
}
});
tooltip-template 只是 tooltip-template-div 和 tooltip-template-span 元素的 div 容器。
$(".tooltip-template-div").hide();
部分工作正常,但 onclick 钩子(Hook)似乎没有任何效果。
谢谢!
最佳答案
您在插入 html 之前添加事件监听器:
尝试颠倒顺序
functionReady: function(instance, helper){
instance.content($('#tooltip-template').html());
$(".tooltip-template-div").hide();
$('.tooltip-template-span').on("click", function(){
console.log("Clicked!");
});
}
关于javascript - 工具提示器中的 onclick 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45612273/