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
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
解决方案 »
- 求jq弹出div优化实现!
- javascript 请教进度条问题。
- 火狐不兼JS代码
- ajax 回调成功后 回调函数执行出错 大家帮忙看看 急
- 如果你用了QQ那么一定要用下网络号
- 菜菜的请教:点击单选框使文本框无效 散分
- 一个n行1列的表格,用鼠标选中文本,其中涉及到好几个单元格,在不改变原有表格内容的前提下,如何得到被选中文本在头一个单元格中的起始
- 一个奇怪的关于Table的offsetHeight问题
- 极度虚心求教...
- 我想通过一个下拉列表的输入来控制另一个文本框的输入,当下拉列选中一值时,使文本框变为不可输入项!
- chrome和IE产生的滑动条 mouseup无法捕获
- 想知道类似 网页游戏 新人任务时的那种导航功能 怎么做
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>"
}
}
});
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('')
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的话,默认是用逗号连接的。