多次重复使用模态火灾

时间:2012-10-31 19:08:08

标签: javascript twitter-bootstrap modal-dialog

我正在使用twitter bootstrap模式插件。模态提交将数据提交给服务器。

出于某种原因,当我多次打开并提交模态时,提交的触发次数与先前打开的模式一样多。

所以,如果我点击一行“更新”。编辑并保存,它会触发一次,因为这是第一次尝试。 如果我然后在第二行单击“更新”。编辑并保存,它会发射两次。 第3次射击3次,4次射击4.等等,等等。

我一直试图解决这个问题已经好几天没找到了。一些指导会让我永远感激不尽。

1 个答案:

答案 0 :(得分:0)

This is how I have fixed this issue:

I have a global variable delete_id=0 just after the <script> tag to store the ID which I want to delete (this can be dynamic to use server side script). I have also added ID myModalAction for the Delete button in my modal HTML.

I have called the modal this way:

$('.delete_row').click(function (){
    delete_id = $(this).attr('id');
    $('#myModal').modal();
});

And for myModalAction:

$('#myModalAction').click(function(e){
    $('#'+delete_id).remove();
    $('#myModal').modal('hide');
});

Complete working code can be found here.

相关问题