1. 程式碼如下:
CSS+JS实现兼容性很好的无限级下拉菜单
for(var x = 1; x
{
var menuid = document.getElementById("選單" x);
menuid.num = x;
類型();
}
函數類型()
{
var menuh2 = menuid.getElementsByTagName("h2");
var menuul = menuid.getElementsByTagName("ul");
var menuli = menuul[0].getElementsByTagName("li");
menuh2[0].onmouseover = 顯示;
menuh2[0].onmouseout = 取消顯示;
menuul[0].onmouseover = 顯示;
menuul[0].onmouseout = 取消顯示;
函數 show()
{
menuul[0].className = "clearfix typeul 區塊"
}
函數 unshow()
{
menuul[0].className = "typeul"
}
for(var i = 0; i
{
menuli[i].num = i;
var liul = menuli[i].getElementsByTagName("ul")[0];
if(liul)
{
類型顯示()
}
}
函數 typeshow()
{
menuli[i].onmouseover = showul;
menuli[i].onmouseout = unshowul;
}
函數 showul()
{
menuli[this.num].getElementsByTagName("ul")[0].className = "block";
}
函數 unshowul()
{
menuli[this.num].getElementsByTagName("ul")[0].className = "";
}
}
腳本>
正文>