我无法找出运行时出了什么问题。在这里,我试图将 JavaScript 重写为 jQuery 语法。究竟是什么不正确?我做错了什么。
遗产 >>
var cssmenuids = ["navmenu"];
function createcssmenu()
{
for (var i = 0; i < cssmenuids.length; i++)
var ultags = document.getElementById(cssmenuids[i]).getElementsByTagName("ul");
for (var t = 0; t < ultags.length; t++)
{
ultags[t].style.top = ultags[t].parentNode.offsetHeight + "-1px";
ultags[t].parentNode.onmouseover = function()
{
this.style.zIndex = 100;
this.getElementsByTagName("ul")[0].style.visibility = "visible";
this.getElementsByTagName("ul")[0].style.zIndex = 0;
}
ultags[t].parentNode.onmouseout = function()
{
this.style.zIndex = 0;
this.getElementsByTagName("ul")[0].style.visibility = "hidden";
this.getElementsByTagName("ul")[0].style.zIndex = 100;
}
}
}
}
if (window.addEventListener)
window.addEventListener("load", createcssmenu, false);
else if (window.attachEvent)
window.attachEvent("onload", createcssmenu);
jQuery 语法 >>
$(document).ready(function ()
{
$('ul#navmenu').height = $('ul#navmenu').parent.height + "-1px";
$('ul#navmenu').parent.bind('mouseover', function ()
{
$(this).css('z-index', 100);
$(this).$('ul')[0].css("visibility", "visible");
$(this).$('ul')[0].css('z-index', 0);
});
$('ul#navmenu').parent.bind('mouseout', function ()
{
$(this).css('z-index', 0);
$(this).$('ul')[0].css("visibility", "hidden");
$(this).$('ul')[0].css('z-index', 100);
});
});
这就是 JSfiddle http://jsfiddle.net/sublay/HCajr/