[英]jquery simple modal and insert on database
i am using jquery.simplemodal-1.1.1 and jquery-1.2.6.min to create a modal popup. 我正在使用jquery.simplemodal-1.1.1和jquery-1.2.6.min创建模式弹出窗口。 this is my problem: i can display the windows, can insert values, fiels, ecc.
这是我的问题:我可以显示窗口,可以插入值,字段,ecc。 i have 2 buttons, save and close.
我有2个按钮,保存并关闭。 when i click on save button, it triggers an event that execute, from code behind, an store procedure that insert some dates on my db.
当我单击保存按钮时,它会触发一个事件,该事件从后面的代码开始执行在数据库中插入一些日期的存储过程。 the problem is, when i click on close button.
问题是,当我单击关闭按钮时。 I open the modal windows, don't do anything and click on cancel.
我打开模式窗口,不执行任何操作,然后单击“取消”。 Close the modal windows.
关闭模式窗口。 i open again the modal windows, fill the fields and click on save.
我再次打开模态窗口,填充字段并单击保存。 The program execute 2 times the event of the save button and then insert 2 times the same information on the DB.
该程序执行两次保存按钮事件,然后在数据库中插入两次相同的信息。 this is the javascript code what i am using:
这是我正在使用的javascript代码:
$(document).ready( function()
{
$("#nuovoT").click(function(ev) {
ev.preventDefault();
$("#TextBoxPrenot").val("");
$("#msg").text("");
//Open the popup container
$("#addTrasport").modal({
onOpen: modalOpenAddCustomer,
onClose: modalOnClose,
persist: true,
containerCss: ({ width: "500px", height: "275px", marginLeft: "-250px" })
});
});
});
function modalOpenAddCustomer(dialog) {
dialog.overlay.fadeIn('fast', function() {
dialog.container.fadeIn('fast', function() {
dialog.data.hide().slideDown('slow');
});
});
dialog.data.find(".modalheader span").html("TITULO");
// if the user clicks "yes"
dialog.data.find("#ButtonConferma").click(function(ev) {
/*Valida se si compila almeno uno dei due campi*/
$("#msg").val("");
if ( ($("#TextBoxTrasp").val() == '') ){
$("#msg").append("* Devi immetere il nome del trasportatore <br/>");
ev.preventDefault;
return false;
}
else{
}
$.modal.close();
$("#ButtonHiddenAddCustomer").click();
});
dialog.data.find("#ButtonCancel").click(function(ev) {
ev.preventDefault();
$.modal.close();
return false;
});
}
What i am doing wrong??? 我做错了什么???
thx in advance!!! 提前谢谢!!!
The problem is that your modalOpenAddCustomer routine is adding the click event onto the button each time the modal is opened. 问题在于,每次打开模式时,您的modalOpenAddCustomer例程都会将click事件添加到按钮上。 Therefore on the second time around, there are 2 click events on the same button.
因此,第二次在同一按钮上有2次单击事件。
Either: Initialise the click event outside the modalOpen... routine - ie within the (document).ready function. 要么:初始化modalOpen ...例程外部的click事件,即在(document).ready函数中。
Or: use ' one
' instead of click: 或者:使用“
one
”代替点击:
dialog.data.find("#ButtonConferma").one('click', function(ev) {
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.