jQuery's autocomplete : customize behavior of “ESCAPE” key press

跟風遠走 提交于 2019-12-14 03:58:49

问题


I am using jQuery's autocomplete plugin and want to customize the behavior when user press the "ESCAPE" key as below,

  1. when user types text to search, its corresponding results are listed. Without selection any result if "ESCAPE" key is pressed, then the search text entered should be removed. [Default Behavior: the search text is retained]
    1. In http://jqueryui.com/demos/autocomplete/#multiple-remote, user can search multiple times. Assume, he has entered a text and has selected a row from the drop down. Now, he searches again, but without selecting any result, he presses "ESCAPE" key, then the search string alone should be removed (and not the previously selected one).

any help is appreciated.


回答1:


something like this

$(document).ready( function() {
    $("#birds").keypress(function (e) {
          if(e.keyCode == 27) {
            $("#birds").val("");
          }}
        });  
});



回答2:


(function( $ ) {
        $( "#input" ).live('keydown', function(e) {    
                var keyCode = e.keyCode || e.which;     
                if(keyCode == 27)
        {
            //Processing
        }
    });
 }( jQuery ));


来源:https://stackoverflow.com/questions/8635463/jquerys-autocomplete-customize-behavior-of-escape-key-press

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!