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
解决方案 »
- 怎样实现倒计时
- 如何动态把一个对象onclick事件赋值给另一个对象
- 为何此处要用单引号,不用双引号?请高人指点!多谢!
- 请问AJAX提示搜索必须建立一个单独的表吗
- 对于一个函数,当执行到函数中间时,有没有什么办法可以暂停等待指定的时间,再执行剩下的代码
- 请问一下javascript如何调用ocx控件?
- window.parent.main.location.reload()?id=1 我想给框架中的页面传递参数该怎么半呀?
- 选择框,文本框传递数量
- 怎样通过botton控制input显示的内容
- 在html中能不能执行一个 exe程序
- 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的话,默认是用逗号连接的。