Jquery点击功能不工作的按钮内弹出窗口

Jquery click function not working for the button inside popover

本文关键字:按钮 窗口 工作 功能 Jquery      更新时间:2023-09-26

当点击id为tagit的按钮时,我试图提醒一条消息。但整个表单出现在引导弹出窗口。我还添加了jquery的警告消息,但它不显示任何警告对话框,但当我在javascript中调用相同的东西时,它会显示警告。但我需要使用jquery。我该怎么做呢?

var htmlcont ='<table class="pop-table"><tr><td><button class="btn btn-warning" id="tagit">FILTER</button></td></tr></table>';
$('[data-toggle="popover"]').popover({content: htmlcont, html: true});    
$("#tagit").click(function(){
      alert("hello this is working");           
});

您需要使用 event delegation ,像这样

$(document).on('click', "#tagit", function() {
   console.log("hello this is working");           
});

动态创建的DOM元素的事件委托。尝试使用直接父选择器轻松快速地遍历

$(document).on('click', '#tagit', function() {
}):