您可以在目的地/酒店 URL 字段中输入:http: //think.thinkhotels.com/
它会自动建议你。功能工作正常。但是,当您按下左/右箭头键时,光标会像往常一样在除 chrome 之外的所有浏览器中向左/向右移动。
我试图修改http://think.thinkhotels.com/autofill/jquery.autocomplete.js中的代码
它有一个代码
$input.bind(($.browser.opera ? "keypress" : "keydown") + ".autocomplete", function(event) {
// a keypress means the input has focus
// avoids issue where input had focus before the autocomplete was applied
hasFocus = 1;
// track last key pressed
lastKeyPressCode = event.keyCode;
switch(event.keyCode) {
case KEY.UP:
event.preventDefault();
if ( select.visible() ) {
select.prev();
} else {
onChange(0, true);
}
break;
我添加了几行,以避免下面左/右箭头中的任何操作是修改后的代码
$input.bind(($.browser.opera ? "keypress" : "keydown") + ".autocomplete", function(event) {
// a keypress means the input has focus
// avoids issue where input had focus before the autocomplete was applied
hasFocus = 1;
// track last key pressed
if(event.which ==KEY.LEFT || event.which == KEY.RIGHT ) {
return true;
}
lastKeyPressCode = event.keyCode;
switch(event.keyCode) {
case KEY.UP:
event.preventDefault();
if ( select.visible() ) {
select.prev();
} else {
onChange(0, true);
}
break;
关键如下
var KEY = {
UP: 38,
DOWN: 40,
DEL: 46,
TAB: 9,
RETURN: 13,
ESC: 27,
COMMA: 188,
PAGEUP: 33,
PAGEDOWN: 34,
BACKSPACE: 8,
LEFT: 37,
RIGHT: 39
};
但问题并没有得到解决。我试过 return false; 这也没有奏效。我试过 event.preventDefault() 也没有用。
任何人都可以找到解决方案吗