关闭jquery模式对话框很慢

时间:2012-06-22 19:47:03

标签: jquery jquery-ui

我有一个模态对话框,我将html表单的内容放在里面。表单有一个提交和取消按钮。我找到了取消按钮,甚至通过点击x很慢来关闭对话框。它只有几秒钟太慢,但它足够长,可以认为有一个问题,疯狂的鼠标答题器可能会疯了。

有没有更好的方法来使用close函数和更好的方法取消更改而不是我正在做的事情:

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>

我可以在这做任何优化吗?提前谢谢。

1 个答案:

答案 0 :(得分:5)

摆脱对话设置中关闭事件的近距离调用:

var $dialog = $('#cameraform').dialog({
    modal:true,
    autoOpen: false,
    resizable:false,
    width: 625,
    close: function() {
      //  $(this).dialog('close'); //this is slow
    }
}); //init dialog

您正在从内部调用close事件,从而导致调用堆栈溢出。

相关问题