关闭jQuery模式对话框很慢 [英] closing jquery modal dialog is slow
问题描述
我有一个模式对话框,在其中放置html表单的内容.表单上有一个提交和取消按钮.我正在找到取消"按钮,或者甚至通过非常慢地按x来关闭对话框.速度虽然只有几秒钟,但足以认为疯狂的鼠标单击器可能发疯了.
I have a modal dialog where I place the contents of an html form inside. The form has a submit and cancel button. I'm finding the cancel button or even closing the dialog by hitting the x quite slow. It is only a few seconds too slow but it is long enough to think there is a problem that crazy mouse clickers might go nuts.
有比我正在使用的关闭功能更好的方法和取消更改的更好方法:
Is there a better way to use the close function and a better way to cancel the changes than what I'm doing:
var $dialog = $('#cameraform').dialog({
modal:true,
autoOpen: false,
resizable:false,
width: 625,
close: function() {
$(this).dialog('close'); //this is slow
}
}); //init dialog
//events
$('.addwebcam').click(function(e) {
$dialog.dialog('open');
});
$(".cancel_changes").click(function() {
$dialog.dialog('close'); //this is slow
});
HTML:
<button class="addwebcam">Add Webcam</button>
<div id="cameraform" title="Add a camera">
...//my form
<button type='button' class='cancel_changes' name='cancel_changes' value='Cancel'>Cancel</button>
</div>
我可以在这里进行任何优化吗?预先感谢.
Any optimization I can do here? Thanks in advance.
推荐答案
摆脱对话框设置中close事件的close调用:
Get rid of the close call from the close event on your dialog setup:
var $dialog = $('#cameraform').dialog({
modal:true,
autoOpen: false,
resizable:false,
width: 625,
close: function() {
// $(this).dialog('close'); //this is slow
}
}); //init dialog
您正在从自身内部调用close事件,从而导致调用堆栈溢出.
You are calling the close event from within itself, thus resulting in a overflow of the call stack.
这篇关于关闭jQuery模式对话框很慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!