在IE 6 7 8 9 下输出option 显示不正常的原因?

Java_xujunjie 2013-04-01 11:36:53
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); // 延时可以减小查询频率
};
}

...全文
69 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
hch126163 2013-04-01
  • 打赏
  • 举报
回复
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.Id txt 是数组。 拼接字符串 用 txt.join('')
Go 旅城通票 2013-04-01
  • 打赏
  • 举报
回复
        $.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>"
                }
            }
        });
Java_xujunjie 2013-04-01
  • 打赏
  • 举报
回复
Java_xujunjie 2013-04-01
  • 打赏
  • 举报
回复
我现在改过来了 但问题依旧存在。在IE8下输出option的时候会掉一截 我不知道为什么。
bbjbepzz 2013-04-01
  • 打赏
  • 举报
回复
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的话,默认是用逗号连接的。
functionsub 2013-04-01
  • 打赏
  • 举报
回复
没搞明白到底哪里显示不正常。

87,910

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧