1

我的浏览器有问题,我在 jsfiddle 中有代码,它通过提供输入来显示匹配结果。但它在 FF 中运行良好而不是在 IE 中

jsfiddle 中的 jquery 版本是 jquery 1.9.1 IE ver。9、FF 24.0版

$("#searchInput").keyup(function () {
    //split the current value of searchInput
    var data = this.value.toLowerCase().split(" ");

    //create a jquery object of the rows
    var jo = $("#selectbox").find("option");
    if (this.value == "") {
        jo.show();
        return;
    }
    //hide all the rows
    jo.hide();

    //Recusively filter the jquery object to get results.
    jo.filter(function (i, v) {
        var $t = $(this);
        for (var d = 0; d < data.length; ++d) {
            if ($t.is(":contains('" + data[d] + "')")) {
                return true;
            }
        }
        return false;
    })
    //show the rows that match.
    .show();
});

http://jsfiddle.net/SBjDb/

4

1 回答 1

1

试试这个:

// on keydown on text box
$("#txtInput").on("keyup", function (e) {                   
    var txt = $(this).val().toLowerCase();  

    //if backspace pressed refresh list
    if (e.which == 8) {
        if (txt.length == 0) {
            renderList(arrText);
        }
    }

    if (txt.length >= 1) {
        var filterList = searchInList(arrText, txt);
        if (filterList.length > 0) {
            renderList(filterList);
        } else {            
            renderList(arrText);
        }
    }                     
});

也可以在 IE9 中工作,在这里摆弄:http: //jsfiddle.net/m25UW/1/

于 2013-10-07T13:04:45.587 回答