我無法找出運行時出了什麼問題。 在這裏,我試圖重新寫JavaScript到jQuery語法。 究竟是什麼不正確?我做錯了什麼。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/
相關問題JavaScript to jQuery syntax Building custom CSS horizontal menu
會發生什麼情況?你會得到什麼錯誤? – sachleen
你能發佈這個代碼運行的相關HTML嗎?將它全部包含在jsfiddle中也會有所幫助。 http://jsfiddle.net –