<!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=gb2312" />
<title>无标题文档</title>
<script language="javascript" type="text/javascript";>
window.onload = function(){
var li = document.getElementsByTagName("li");
for (var j=0; j < li.length; j++){
li[i].onmouseover = function(){
this.style.backgroundcolor='blue';
};
li[i].onmouseout = function(){
this.style.backgroundColor='white';
};
}
};
</script>
</head><body>
<ul>
<li id="ee">everywhereeverywhere</li>
<li id="text">texttexttexttexttexttext</li>
<li id="text">texttexttexttexttexttext</li>
</ul>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script language="javascript" type="text/javascript";>
window.onload = function(){
var li = document.getElementsByTagName("li");
for (var j=0; j < li.length; j++){
li[i].onmouseover = function(){
this.style.backgroundcolor='blue';
};
li[i].onmouseout = function(){
this.style.backgroundColor='white';
};
}
};
</script>
</head><body>
<ul>
<li id="ee">everywhereeverywhere</li>
<li id="text">texttexttexttexttexttext</li>
<li id="text">texttexttexttexttexttext</li>
</ul>
</body>
</html>
解决方案 »
- 这么一小段代码 ie怎么都不兼容 没有用到任何复杂的函数 都是些for if 这样ie都不能执行啊~~~
- 火狐不能用javascript的问题
- [**醒目**]希望CSDN能把社区左边的导航页面改进一下,经常出问题啊
- 一个函数重名问题,同一页文件中和独立js文件中的区别
- 送分题:100分求(渐隐渐现的文字效果,不要带闪烁,不要花哨,就朴素的显示又消失),在线等,马上给分!
- 在JS中怎么声明一个数组?我如下的方法不对,是在JAVA中声明的,JS如何声明?
- js里面怎么进行类型转换?如 :element -- input
- <td onmouseover="this.title=...>中onmouseover的时候,如何得到当前单元格的内容并赋给title?
- 有问题要问
- litebox弹窗插件怎么调用关闭
- 怎样使用JS发送一个空HTTP请求,目的是为了保持长连接。多谢
- JS写的一段倒计时.有疑似客户端延迟现象.但......
li[i].onmouseover = function(){
this.style.backgroundcolor='blue';
};
li[i].onmouseout = function(){
this.style.backgroundColor='white';
};你for循环里面变量是j 而遍历集合的时候li[i] 用的是i. 当然有问题啦。
window.onload = function(){
var li = document.getElementsByTagName("li");
for (var j=0; j < li.length; j++){
li[j].onmouseover = function(){
this.style.backgroundcolor='blue';
};
li[j].onmouseout = function(){
this.style.backgroundColor='white';
};
}
};
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script language="javascript" type="text/javascript";>
window.onload = function(){
var li = document.getElementsByTagName("li");
for (var i=0; i< li.length; i++){
li[i].onmouseover = function(){
this.style.backgroundColor='blue';
};
li[i].onmouseout = function(){
this.style.backgroundColor='white';
};
}
};
</script>
</head><body>
<ul>
<li id="ee">everywhereeverywhere</li>
<li id="text">texttexttexttexttexttext</li>
<li id="text">texttexttexttexttexttext</li>
</ul>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script language="javascript" type="text/javascript";>
window.onload = function(){
var li = document.getElementsByTagName("li");
for (var j=0; j < li.length; j++){ li[j].onmouseover = function(){
this.style.background= '#00ff00';
};
li[j].onmouseout = function(){
this.style.background= '#ddff00';
};
}
};
</script>
</head><body>
<ul>
<li id="ee">everywhereeverywhere</li>
<li id="text">texttexttexttexttexttext</li>
<li id="text">texttexttexttexttexttext</li>
</ul>
</body>
</html>
主要有两个问题:
1)li[i] 这里用i,可for循环中使用的是j,该打屁股;
2)li[i].onmouseover = function(){
this.style.backgroundcolor='blue';
};
的backgroundcolor应该为backgroundColor,C要大写~~~粗心大萝卜,开心了不?
<!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=gb2312" />
<title>无标题文档</title>
<script language="javascript" type="text/javascript";>
window.onload = function(){
var li = document.getElementsByTagName("li");
for (var i=0; i < li.length; i++){
li[i].onmouseover = function(){
this.style.backgroundColor='blue';
};
li[i].onmouseout = function(){
this.style.backgroundColor='white';
};
}
};
</script>
</head><body>
<ul>
<li id="ee">everywhereeverywhere</li>
<li id="text1">texttexttexttexttexttext</li>
<li id="text2">texttexttexttexttexttext</li>
</ul>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script language="javascript" type="text/javascript";>
window.onload = function(){
var li = document.getElementsByTagName("li");
for (var i=0; i< li.length; i++){
li[i].onmouseover = function(){
this.style.backgroundColor='blue';
};
li[i].onmouseout = function(){
this.style.backgroundColor='white';
};
}
};</script>
</head><body>
<div>
<ul>
<li id="ee">everywhereeverywhere</li>
<li id="text">texttexttexttexttexttext</li>
<li id="text">texttexttexttexttexttext</li>
</ul>
</div>
</body>
</html>