更改模态对话框的Jquery键绑定

时间:2011-11-28 19:17:01

标签: javascript jquery jquery-ui

我有一个模态对话框。我需要在与Easape键不同的组合键上关闭对话框。我怎样才能做到这一点。

我有以下代码,但从未执行过。任何线索为什么?

var agreeDialog = $j('#termsOfAgreementConfirm').dialog({
            modal: true,
            autoOpen:false,
            resizable:false,
            width : 1000,
            height :400,
            stack:false,
            title:"Terms of Usage",
              open: function(event, ui) { $j('.ui-dialog-titlebar-close').hide(); },
            buttons: {

                Disagree: function() {
                    disagree.dialog('open');
                    disagree.dialog('moveToTop');

                },
                Agree: function() {
                    $j(this).dialog('close');
                    $j.cookie("agree","Y");
                    new Ajax.Request('/test/user/ajaxUpdateAgreementForUser',
                            {
                                onSuccess:function(resp){
                                },
                                onError: function(resp) {
                                    alert("Error:" + resp.toJSON());
                                    return;
                                },
                                asynchronous:true,
                                evalScripts:true
                           });
                    $j(this).dialog('close');

                }
            }
        });
        if (result == "false" && $j.cookie("agree")== null) {
           agreeDialog.dialog('open')
           agreeDialog.keyup(function e() {
                alert(e.keyCode);
           });
        }

1 个答案:

答案 0 :(得分:1)

您需要捕捉身体上的关键事件,然后触发关闭事件。看看这个例子。按任意键将关闭对话框。你必须在宣言之外做。

http://jsfiddle.net/yu8Sg/

$('body').keyup( function(e) {    
    $('#dialog').dialog('close');
});
相关问题