简体   繁体   English

如何修改这个jQuery?

[英]How to modify this jquery?

I have got a script for suggestion box. 我有一个建议框脚本。 Its working great but problem with this I want to modify it for upkey and downkey event. 它的工作很好,但与此有关的问题,我想修改它为upkey和downkey事件。 Its just giving suggestion even not working for mouse click event. 它只是给出建议,甚至不适用于鼠标单击事件。

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 的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"> &nbsp; </div>

As I am new with jquery, may I have idea how to modify it further for mouse click or keyboard arrow keys. 由于我是jquery新手,请问我是否有办法进一步修改鼠标单击或键盘箭头键。

Why reinvent the wheel - have you looked at jquery ui autocomplete? 为什么要重新发明轮子-您是否看过jquery ui自动完成功能? http://jqueryui.com/demos/autocomplete/ http://jqueryui.com/demos/autocomplete/

I think this may help you with keyboard arrow keys (register key event handling) 我认为这可以帮助您使用键盘箭头键(注册键事件处理)

// 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;
        }
});

this link will help you with the keycode: 该链接将帮助您使用键码:

http://www.cambiaresearch.com/c4/702b8cd1-e5b0-42e6-83ac-25f0306e3e25/javascript-char-codes-key-codes.aspx http://www.cambiaresearch.com/c4/702b8cd1-e5b0-42e6-83ac-25f0306e3e25/javascript-char-codes-key-codes.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM