浏览器问题搜索代码在Firefox中不在Internet Explorer中

时间:2013-10-07 12:07:21

标签: jquery internet-explorer

我有浏览器问题,我在jsfiddle中有代码,通过提供输入显示匹配结果。 但它在FF中工作正常而不是在IE中

jsfiddle中的jquery版本是jquery 1.9.1 IE版本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/

1 个答案:

答案 0 :(得分: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/