function BindBrand() {
        var Timer = function () {
            this.startTime = (new Date()).getTime();
        };
        Timer.prototype.end = function () {
            return (new Date()).getTime() - this.startTime;
        };        var initTime = new Timer();
        var engine = pinyinEngine(); // 初始化搜索引擎
        initTime = initTime.end();
        var txt = [];
        var tmplCache, setCacheTime
        $.ajax({
            url: "/ashx/GetCarBasicBrand.ashx",
            success: function (data) {
                //alert(eval(data));
                var list = eval(data)
                for (var i in list) {
                    setCacheTime = new Timer();
                    txt.push("<option value='" + list[i].Id + "' title='" + list[i].Name + "'>"+list[i].Name+"</option>");
                    engine.setCache([list[i].Name], list[i]);
                    setCacheTime = setCacheTime.end();
                    tmplCache = "<select size='10' name='ListBox1' id='ListBox1' style='width:100px;'>"+txt+"</select>"
                }
            }
        });        // 拼音快速查询
        var pinyinSearch = function (keyword, callback) {
            var time = new Timer();
            var txt = [];
            var len = 0;
            //alert(tmplCache);
            if (keyword === '') {
                txt = tmplCache;
            } else {
                engine.search(keyword, function (data) {
                    txt.push("<option value='" + data.Id + "' title='" + data.Name + "'>"+data.Name+"</option>");
                    len++;
                });
            };
            callback(txt);
        };        var timer;
        var searchInput = document.getElementById('brandsearch');
        var unisContent = document.getElementById("ListBox1");
        var oldVal = searchInput.value;        // 绑定输入事件
        searchInput.oninput = searchInput.onpropertychange = function () {
            var val = searchInput.value;
            if (val === oldVal) return;
            oldVal = searchInput.value;            clearTimeout(timer);
            timer = setTimeout(function () {
                pinyinSearch(val, function (html) {
                    alert(html);
                    unisContent.innerHTML = html;
                });
            }, 40); // 延时可以减小查询频率
        };
    }ie

解决方案 »

  1.   

            $.ajax({
                url: "/ashx/GetCarBasicBrand.ashx",
                cache:false,/////////////////防止缓存
                success: function (data) {
                    //alert(eval(data));
                    var list = eval(data)
                    for (var i in list) {
                        setCacheTime = new Timer();
                        txt.push("<option value='" + list[i].Id + "' title='" + list[i].Name + "'>" + list[i].Name + "</option>");
                        engine.setCache([list[i].Name], list[i]);
                        setCacheTime = setCacheTime.end();
                        tmplCache = "<select size='10' name='ListBox1' id='ListBox1' style='width:100px;'>" + txt + "</select>"
                    }
                }
            });
      

  2.   

      var list = eval(data)
                    for (var i in list) {
                        setCacheTime = new Timer();
                        txt.push("<option value='" + list[i].Id + "' title='" + list[i].Name + "'>"+list[i].Name+"</option>");
                        engine.setCache([list[i].Name], list[i]);
                        setCacheTime = setCacheTime.end();
                        tmplCache = "<select size='10' name='ListBox1' id='ListBox1' style='width:100px;'>"+txt+"</select>"
                    }list是什么格式,确定是 list[i].Id
    而不是 i.Idtxt 是数组。 拼接字符串 用 txt.join('')
      

  3.   

     for (var i in list) {
                        setCacheTime = new Timer();
                        txt.push("<option value='" + list[i].Id + "' title='" + list[i].Name + "'>"+list[i].Name+"</option>");
                        engine.setCache([list[i].Name], list[i]);
                        setCacheTime = setCacheTime.end();                }
                        tmplCache = "<select size='10' name='ListBox1' id='ListBox1' style='width:100px;'>"+txt.join('')+"</select>"红色部分是不是要放在循环外面啊,还有txt如果不用join的话,默认是用逗号连接的。
      

  4.   

     我现在改过来了 但问题依旧存在。在IE8下输出option的时候会掉一截  我不知道为什么。