日期:2014-05-17  浏览次数:20369 次

下句jquery 换成js 得怎么写啊
下句jquery 换成js 得怎么写啊  

$(function () {
  $("li:has(ul)").hover(
function () {
  $(this).children("ul").show();
},
function () {
  $(this).children("ul").hide();
})
  })

------解决方案--------------------
JScript code

window.onload=function(){ 
     var dom=document.getElementsByTagName("li"); 
     for(var i=0;i<dom.length;i++){ 
        if (dom[i].childNodes.length > 0)
        {
            for (var j=0,l=dom[i].childNodes.length;j<l ;j++ )
            {
                if (dom[i].childNodes[j].tagName == "UL")
                {
                    dom[i].onmouseover=function(){ 
                        for (var i=0,l=this.childNodes.length;i<l ;i++ )
                        {
                            if (this.childNodes[i].tagName == "UL")
                            {
                                this.childNodes[i].style.display='';
                            }
                        }
                    }
                    dom[i].onmouseout=function(){ 
                        for (var i=0,l=this.childNodes.length;i<l ;i++ )
                        {
                            if (this.childNodes[i].tagName == "UL")
                            {
                                this.childNodes[i].style.display='none';
                            }
                        }
                    }
                }
            
             
            }
        }
          
     } 
   }