开发者

How to Deactivate "Enter Key" when using jQueryUI Dialog Confirmation

I am having some issue with the enter key within IE6 together with the jQuery UI Dialog confirmation box that has just an "Ok" button on it.

$("#myBox").dialog({
            autoOpen: false,
            closeOnEscape: false,
            resizable: false,
            modal: true,
            draggable: false,
            position:  ["center", 100],
            buttons: {
              'Ok': function() { 
                      $(this).dialog("close"); 
                      closeReq();
                    }
        }
    });

Basically, I only want the dialog box together with any additional function calls against the "Ok" to close/fire function, only when the user clicks on the "Ok" but开发者_StackOverflow中文版ton.

At the moment, I allow the user to press the "Enter" to fire off the retrieval of some info and then based on some validation of this data, I produce a modal jQuery UI dialog box but seems to autmatically close from the user's pressing of the "Enter Key" from the start.

How can I prevent this from occuring, i.e. deactivate the "Enter" key in IE6 for this jQueryUI Dialog Message box?

Thanks.


At the moment, I allow the user to press the "Enter" to fire off the retrieval of some info and then based on some validation of this data

whereever you do that, call

.preventDefault();
.stopPropagation();

within your event handler. Returning false is like a shortcut for that.


Good you solved your problem. Here what worked for me:

// Kills an event's propagation and default action. Scott Andrew
function knackerEvent(eventObject) {
    if (eventObject && eventObject.stopPropagation) {
        eventObject.stopPropagation();
    }
    if (window.event && window.event.cancelBubble ) {
        window.event.cancelBubble = true;
    }

    if (eventObject && eventObject.preventDefault) {
        eventObject.preventDefault();
    }
    if (window.event) {
        window.event.returnValue = false;
    }
}  


Managed to track this down which solved my problem, please refer to this solution.

Looks like preventDefault is not recognized by IE6.

Thanks to @jAndy for your assistance.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜