[英]How to modify this jquery?
我有一個建議框腳本。 它的工作很好,但與此有關的問題,我想修改它為upkey和downkey事件。 它只是給出建議,甚至不適用於鼠標單擊事件。
function lookup(inputString) {
if(inputString.length == 0) {
// Hide the suggestion box.
$('#suggestions').hide();
} else {
$.post("rpc.php", {queryString: ""+inputString+""}, function(data){
if(data.length >0) {
$('#suggestions').show();
$('#autoSuggestionsList').html(data);
}
});
}
} // lookup
function fill(thisValue) {
$('#inputString').val(thisValue);
setTimeout("$('#suggestions').hide();", 50);
}
的HTML
<input type="text" size="30" value="" id="inputString" onkeyup="lookup(this.value);" onblur="fill();" />
<div class="suggestionsBox" id="suggestions" style="display: none;"> <img src="upArrow.png" style="position: relative; top: -12px; left: 30px;" alt="upArrow" />
<div class="suggestionList" id="autoSuggestionsList"> </div>
由於我是jquery新手,請問我是否有辦法進一步修改鼠標單擊或鍵盤箭頭鍵。
為什么要重新發明輪子-您是否看過jquery ui自動完成功能? http://jqueryui.com/demos/autocomplete/
我認為這可以幫助您使用鍵盤箭頭鍵(注冊鍵事件處理)
// Handling keybinding keydown.
$(document).keydown(function(e){
switch(e.keyCode){
case 38: //this is (UP) pressed down
// do the action you want.
break;
}
});
// Handling keybinding keyup.
$(document).keyup(function(e){
switch(e.keyCode){
case 38: //this is (UP) pressed down
// do the action you want.
break;
}
});
該鏈接將幫助您使用鍵碼:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.