简体   繁体   中英

How can I stop jquery ui dialog executes on pressing Enter

I have an input field that I have bound an event on keypressed, but when I press Enter (to execute the event for the input) two dialogs from jQuery UI pops open and ruin my variables. How can I stop the events bound to the enter key for dialogs?

$("#itemSample").on('keypress', function (e) {
    if (e.keyCode == 13 && $("#itemSample").val().trim().length > 0) {
        //do something               
    }
});

On the parameter 'e' (Event) you have the necessary functions:

$("#itemSample").on('keypress', function (e) {
    if (e.keyCode == 13 && $("#itemSample").val().trim().length > 0) {
      // You probably need just one of the following two lines:
      e.preventDefault();
      e.stopPropagation();           
    }
});

For more info: http://css-tricks.com/return-false-and-prevent-default/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM