在IE 6 7 8 9 下输出option 显示不正常的原因?
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); // 延时可以减小查询频率
};
}