//模糊搜索开始
var sFind = document.getElementById("show").value;
if (sFind == ""||sFind == " ") {
alert("不能为空.");
document.getElementById('ff').style.display = 'none';
}
if (sFind != "") {
var nPos;
var vResult = []; //定义一个放置搜索结果的数组
for (var i in temp) {
var sTxt = temp[i] || '';
nPos = find(sFind, sTxt);
if (nPos >= 0) {
vResult[vResult.length] = sTxt;
}
}
}
if (vResult.length == 0) {
alert("搜索词不存在.");
document.getElementById('ff').style.display.border.color = '#fff';
}
else {
//使搜索结果以li标签排列
var list=[]; //定义一个列表数组
for(i=0;i<vResult.length;i++)
{
list+="<li>"+vResult[i]+"</li>";
}
list="<ul>"+list+"</ul>";
document.getElementById("ff").innerHTML = list;
document.getElementById('ff').style.display = 'block';
}
document.getElementById('downmenu1').style.display = 'none';
}
function ss(ss) {
document.getElementById("show").value = ss;
}
function find(sFind, sObj) {
var nSize = sFind.length;
var nLen = sObj.length;
var sCompare;
if (nSize <= nLen) {
for (var i = 0; i <= nLen - nSize + 1; i++) {
sCompare = sObj.substring(i, i + nSize);
if (sCompare == sFind) {
return i;
}
}
}
return -1;
}
//模糊搜索结束
网友评论