0

我需要能够根据输入文本值动态填充 html 选择。一旦文本框值超过 8 个字符,这需要自动触发。用户不必按 Tab 或单击即可查看填充的值。这是我到目前为止所拥有的,但这仅在文本框失去焦点时才会触发。

//Html code
<input id=InputText name=InputText onblur="populateListBox();" onchange="CheckInputLength();" onkeydown="CheckInputLength();" value="" onfocus="this.select();">

//Javascript代码

function CheckInputLength()
{
    if($("#InputText").val().length >= 8)
        populateListBox();
}

function populateListBox()
{   
            $.get("???", function( data ) {
                $('#listBox').children().remove();
                var options = data;

                $("#listBox").append( options );
                $("#listBox").html( data );

            });

}
4

2 回答 2

0

我会检查 Select2 听起来它具有您正在寻找的所有功能以及一些功能:http: //ivaynberg.github.com/select2/

$("#InputText").select2({
  minimumInputLength: 8,
  ajax: {
    url: "???",
    // your other options
  }
});
于 2012-06-08T19:58:21.460 回答
0
$('#InputText').keypress(function (event) {
    var $inputText = $(this);
    // Before keypress.
    setTimeout(function () {
        // After keypress.
        if ($inputText.val().length >= 8) { populateListBox(); }
    }, 0);
});
于 2012-06-08T20:00:18.683 回答