我希望自動完成的行爲像這樣。輸入鍵上的JQuery自動完成操作
當用戶輸入在文本框中沒有什麼應該發生的東西.. 自動完成建議列表應該只出現在用戶已經寫完在文本框中 ,然後按回車鍵..
任何想法如何做到這一點..或者在哪裏更改代碼..
我希望自動完成的行爲像這樣。輸入鍵上的JQuery自動完成操作
當用戶輸入在文本框中沒有什麼應該發生的東西.. 自動完成建議列表應該只出現在用戶已經寫完在文本框中 ,然後按回車鍵..
任何想法如何做到這一點..或者在哪裏更改代碼..
第1名:
更改jquery.ui.autocomplete.js文件,以接受改變具有簽名的方法進入鍵,下面
.bind(」 keydown.autocomplete「,功能(事件)
並將其更改爲以下代碼
case keyCode.ENTER:
case keyCode.NUMPAD_ENTER:
// when menu is open and has focus
if (self.menu.active) {
// #6055 - Opera still allows the keypress to occur
// which causes forms to submit
suppressKeyPress = true;
event.preventDefault();
}
//passthrough - ENTER and TAB both select the current element
要
case keyCode.ENTER:
case keyCode.NUMPAD_ENTER:
// when menu is open and has focus
if (self.menu.active) {
// #6055 - Opera still allows the keypress to occur
// which causes forms to submit
suppressKeyPress = true;
event.preventDefault();
}
else {
clearTimeout(self.searching);
self.searching = setTimeout(function() {
// only search if the value has changed
self.selectedItem = null;
self.search(null, event);
}, self.options.delay);
}
//passthrough - ENTER and TAB both select the current element
STEP:2 更改自動完成結合作爲
$('.SearchAddresses').autocomplete({
// Your bind code by setting required parameters
search: function (event, ui) {
var key = CheckBrowser(event);
if (key == 13)
return true;
else
return false;
}
});
function CheckBrowser(e) {
if (window.event)
key = window.event.keyCode; //IE
else
key = e.which; //firefox
return key;
}
SETP:3 如果你在asp.net窗體控件中使用它,你也可以使用它。
$(document).ready(function() {
$("form").keypress(function (e) {
var key = CheckBrowser(e);
if (key == 13) {
e.preventDefault();
return false;
}
else {
return true;
}
});
});
可能動態綁定/取消綁定控件。例如。在按下回車鍵之前不要讓它成爲自動完成功能?要麼只讀源文件夾,要麼刪除文本更改,直到再次按下Enter鍵?我敢肯定,您可以手動觸發自動填充事件,從而顯示下拉菜單。
我會建議檢查「輸入密鑰」的按鍵事件。當按下「Enter」鍵時,觸發自動完成功能,如下所示。
$(#inputBoxId).keypress(function(e) {
if(e.which == 13) {
$("#elementId").autocomplete({
//............... bind autocomplete and write your code
});
}
});
試試這個,可能對你有幫助。
我試過這個,但沒有得到結果.. – 2012-07-31 06:06:36
我們需要代碼來建議「在哪裏更改代碼」 – 2012-07-10 15:28:33