Twitter BootStrap确认不适用于动态生成的元素 [英] Twitter BootStrap Confirmation not working for dynamically generated elements

查看:139
本文介绍了Twitter BootStrap确认不适用于动态生成的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用DataTable的页面加载时生成的动态内容. 在表中,我使用了引导程序确认. 要在脚本下面加载它.

I am using DataTable's with dynamic content generated on page load. In table I have used bootstrap confirmation. To load it below script.

$( document ).ajaxStop(function() {
    $(document).find('[data-toggle="confirmation"]').confirmation();
});

它会打开确认框,但是当单击是"或否"时,它不起作用.

It opens confirmation box, but when clicking on "Yes" or "No" , it's not working.

我有下面的代码来检测已确认"事件.

I have below code to detect 'Confirmed' event.

$(document).ready(function(){
    $(document).find('.delete-record').on('confirmed.bs.confirmation', function() {
        var thisEl = $(this);
        deleteForm($(this).attr('data-delid'));
    });
});

这正在工作

$(document).ajaxStop(function(){
    $(document).find('.delete-record').on('confirmed.bs.confirmation', function() {
        var thisEl = $(this);
        deleteForm($(this).attr('data-delid'));
    });
});

document.ready怎么了?

What's wrong with document.ready ?

我在其他页面上使用与document.ready相同的代码,但是没有DataTable,它是HTML DIV结构.

I have same code with document.ready working on other page, but there is no DataTable, it's HTML DIV structure.

推荐答案

尝试稍微更改事件绑定,以便使用备用$.on语法将其绑定到每个现有和将来的.delete-record元素.

Try changing your event binding slightly so it's bound for every existing and future .delete-record element using the alternate $.on syntax.

$(document).ready(function(){
    $('body').on('confirmed.bs.confirmation', '.delete-record', function() {
        deleteForm($(this).attr('data-delid'));
    });
});

不知道您的页面结构,我选择绑定到body,但是您可以将其绑定到表的任何父元素.

Not knowing your page structure I opted to bind to body, but you can bind it to any parent element of your table.

这篇关于Twitter BootStrap确认不适用于动态生成的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆