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);
最好能每句写出下注释。谢谢啦,主要就是cssRule.selectorText.replace(/LI:hover/gi, "LI.iehover");和document.styleSheets[i].rules.length 这样的不懂,没接触过。

解决方案 »

  1.   

    参考
    http://topic.csdn.net/u/20111214/21/0affcb2b-e325-427e-b53e-47e286a6c057.htmla:hover是指鼠标放在超连接时候超连接的样式,这里首先是
    把css里面的 LI:hover,替换成 "LI.iehover"
    并且利用鼠标事件去模仿,最终是得到li鼠标经过和不经过时的两个不同样式
      

  2.   

    cssRule.selectorText.replace(/LI:hover/gi, "LI.iehover"); 
    这句是用正则匹配,将selectorText里所有 LI:hover  替换成  LI.iehover
    document.styleSheets[i].rules.length
    这句的意思是统计document里的样式表的长度。