问题
I am using jQuery's autocomplete plugin and want to customize the behavior when user press the "ESCAPE" key as below,
- 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]
- 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