IE6下支持li:hover的鼠标滑过效果,方法绝对正确,我已测试过
2012-06-27 09:21
465 查看
<!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>IE的hover效果实现</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>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>IE的hover效果实现</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>
相关文章推荐
- 解决IE6不支持li:hover鼠标经过的效果
- 使IE6支持:hover效果使用li:hover或div:hover
- JavaScript 解决 IE6 不支持 li:hover 的方法
- IE6不支持li:hover的解决方法
- IE6不支持hover的解决方法
- 通过CSS效果:隔行变色和鼠标掠过高亮,学习JQuey的css()、hover()方法
- Jquery的hover方法让鼠标经过li时背景变色
- 完美解决IE6不支持hover的方法
- 利用position定位和hover实现鼠标滑过文字覆盖图片效果
- IE6.0 不支持LI:HOVER的解决方法
- jQuery实现DIV响应鼠标滑过由下向上展开效果示例【测试可用】
- Jquery的hover方法让鼠标经过li时背景变色
- jQuery实现鼠标滑过预览图片大图效果的方法
- 一个解决ie6不支持:hover、属性选择器等问题的方法
- IE6中盒子绝对定位不起效果的解决方法
- IE6.0 不支持LI:HOVER的解决方法
- 表格的hover效果,IE6下用JS解决。--- 当鼠标移动到表格行时出现行背景颜色。
- VB6.0对鼠标滚轮不支持的解决方法[转]已经测试work
- JS解决IE6不支持li:hover的代码
- IE6中盒子绝对定位不起效果的解决方法