JS解决IE6不支持li:hover的代码

<script language="javascript">
stuHover = function() {
var cssRule;
var newSelector;
for (var i = 0; i < document.styleSheets.length; i++)
 for (var x = 0; x < document.styleSheets[i].rules.length ; x++)
{
cssRule = document.styleSheets[i].rules[x];
if (cssRule.selectorText.indexOf("LI:hover") != -1)
{
 newSelector = cssRule.selectorText.replace(/LI:hover/gi, "LI.iehover");
 document.styleSheets[i].addRule(newSelector , cssRule.style.cssText);
}
 }
var getElm = document.getElementById("nav").getElementsByTagName("LI");
for (var i=0; i<getElm.length; i++) {
 getElm[i].onmouseover=function() {
this.className+=" iehover";
 }
 getElm[i].onmouseout=function() {
this.className=this.className.replace(new RegExp(" iehover\\b"), "");
 }
}
}
if (window.attachEvent) window.attachEvent("onload", stuHover);
</script>
 
红色字体为DIV的 ID
对于CSS+DIV 做出来的二级菜单的时候,这个代码绝对管用..
posted @ 2013-11-07 14:22  不再犹豫、  阅读(182)  评论(0编辑  收藏  举报