天天看點

html隐藏搜尋框的字型,搜尋框的純前端實作網頁跳轉

@半路獨行:

var input, filter, ul, li, a, i, isOutUl, isOutInput;// 聲明變量

input = document.getElementById('myInput');//擷取搜尋框的輸入值

ul = document.getElementById("myUL");//下拉框

li = ul.getElementsByTagName('li');

function myFunction() {

isOutInput = false;

isOutUl = false;

filter = input.value.toUpperCase();//将搜尋框中的值轉換成大寫

// 循環所有清單,查找比對項

for (i = 0; i < li.length; i++) {

a = li[i].getElementsByTagName("a")[0];//取得連結

if (a.innerHTML.toUpperCase().indexOf(filter) > -1 && filter != '') {

li[i].style.display = "";//如果是需要,則顯示

ul.style.display = "";

} else {

li[i].style.display = "none";//否則,不顯示

}

}

}

ul.onmouseleave = function () {

isOutUl = true;

leave(isOutUl);

}

input.onmouseleave = function () {

isOutInput = true;

leave(isOutInput);

}

var leave = function () {

if (isOutUl && isOutInput) { ul.style.display = "none" };

}

ul.onmouseenter = function () {

isOutUl = false;

}

input.onmouseenter = function () {

isOutInput = false;

}

var leave = function () {

setTimeout(function () {

if (isOutUl && isOutInput) { ul.style.display = "none" };

}, 50)

}

都改過來了呀