日省其身,有则改之,无则加勉!
当前位置:首页网络技巧 - IE6 li:hover兼容问题

IE6 li:hover兼容问题

li:hover不支持IE6,我相信很多站长都遇到过,很多做好的效果(在IE7上实现的效果)不得不修改,我也被这个问题困扰着,尝试过各种办法都没有解决,今天终于解决了。完美支持 IE6、IE7、IE8、FIREFOX。


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>by commy </title>
<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>
<style type="text/css">
li:hover { background:#00CC00; display:block; }
</style>
</head><body >
<div id="nav">
<ul><li>让IE6支持li:hover的JS代码</li></ul>
</div>
</body>
</html>


 


分享到: 更多
标签:lihover兼容
分类:网络技巧| 发布:你认错人了| 点击: | 发表时间:2011-12-22
本文链接:http://www.netcento.com/archive/305.html
上一篇:« switch&hcp服务器为不同的vlan分配IP地址
下一篇:如何关闭禁止mscorsvw.exe »

相关文章

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。