多次重用模态火 [英] reusing modal fires multiple times

查看:94
本文介绍了多次重用模态火的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用twitter bootstrap模式插件.模态中的提交将数据提交到服务器.

I'm using the twitter bootstrap modal plugin. The submit from the modal submits data to the server.

由于某种原因,当我多次打开并提交模态时,提交的触发次数是之前打开模态的次数.

For some reason, when I open and submit the modal multiple times the submit is firing as many times as the modal has been opened previously.

因此,如果我在一行上单击更新".编辑并保存,因为这是第一次尝试,它会触发一次. 如果我再单击第二行上的更新".编辑并保存,触发两次. 第三次发射3次,发射4次.依此类推.

So if I click "update" on a row. Edit and save, it fires once since that's the first attempt. If I then click "update" on a second row. Edit, and save, it fire's twice. 3rd time fires 3 times, 4 fires 4. So on, so forth.

我几天来一直在尝试解决此问题,但没有发现任何问题.一些指导会让我永远感激不已.

I've been trying to resolve this for days now and have found nothing. Some guidance would be leave me eternally grateful.

推荐答案

这是我解决此问题的方法:

This is how I have fixed this issue:

<script>标记之后,我有一个全局变量delete_id=0,用于存储要删除的ID(使用服务器端脚本时可以动态更改).我还在我的模式HTML中为Delete按钮添加了ID myModalAction.

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();
});

对于myModalAction:

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

可以在此处找到完整的工作代码.

Complete working code can be found here.

这篇关于多次重用模态火的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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