Javascript 单击Bootgrid分页按钮时引发事件?

Javascript 单击Bootgrid分页按钮时引发事件?,javascript,jquery,jquery-bootgrid,Javascript,Jquery,Jquery Bootgrid,当单击JQuery Bootgrid分页元素中的按钮时,我很难触发事件。我相信我无法正确地将元素作为目标,以便处理程序知道我已经单击了分页。我已经尝试了以下变化和更多: $(document).on('click', "#grid-footer .button", function () { alert("You clicked the pagination button!"); }); $(document).on('click', "#grid-footer a", function

当单击JQuery Bootgrid分页元素中的按钮时,我很难触发事件。我相信我无法正确地将元素作为目标,以便处理程序知道我已经单击了分页。我已经尝试了以下变化和更多:

$(document).on('click', "#grid-footer .button", function () {
   alert("You clicked the pagination button!");
});
$(document).on('click', "#grid-footer a", function () {
   alert("You clicked the pagination button!");
})
$(document).on('click', "#grid-footer a .button", function () {
   alert("You clicked the pagination button!");
})
$(document).on('click', "#grid-footer .pagination", function () {
   alert("You clicked the pagination button!");
})
$(document).on('click', "#grid-footer .pagination > li > a", function () {
   alert("You clicked the pagination button!");
})    

单击分页按钮时,所有这些都不会触发警报。当单击分页时,是否有人能找到触发事件的正确选择器?下面是一个包含最简单的bootgrid和分页元素的示例。

我没有使用bootgrid,但我只是快速浏览了一下文档。当前代码无法工作的原因是在生成内容之前添加了eventListener。因此,您应该首先为加载内容时添加eventListener

在这个eventListener中,您可以为分页添加一个eventListener,如下所示

var rowIds = [];
var grid = $("#grid").bootgrid({
    selection:true,
    multiSelect: true,
    rowSelect: true,
    rowCount: 3 
}).on("loaded.rs.jquery.bootgrid", function(e){
    console.log("Bootgrid Loaded")
    $("#grid-footer .button").on('click', function () {
        alert("You clicked the pagination button!");
    });
});
您可以使用许多EventListener,请查看


这是一个更新的事件处理程序,整个过程都在运行。

Hm,但是分配事件处理程序OP的技术使用了-
$(文档)。在('click',“#grid footer.button”
上,而不是
$('#grid footer.button'))。单击
-对于以后添加的元素,这不是应该可以吗?@James Yup,你似乎是对的。我认为这里的理由是内容加载在
iframe
中,但我可能错了?