代码如下:
<!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><style type="text/css">
<!--
#Layer1 {
position:absolute;
left:3px;
top:7px;
width:451px;
height:35px;
z-index:1;
}
-->
</style>
</head>
<SCRIPT LANGUAGE="JavaScript">
<!--
function changeColor(j){
var arr = document.all("state");
alert(arr.length);
for(var i=0;i <arr.length;i++){ if(i==j-1){
arr[i].style.cssText="font-weight:bold;color:#ffcc00;";
arr[i].style.backgroundColor="#006600";
} else{
arr[i].style.cssText="font-weight:bold;color:#ffffff;";
arr[i].style.backgroundColor="#33cc00";
}
}
}
//-->
</SCRIPT><body>
<table width="437" border="0" cellspacing="0">
<tr>
<TD height="22" align="center" bgcolor="#33cc00" id=state style="font-weight:bold;color:#ffffff;" onMouseMove="changeColor(1)">首页</TD>
<TD align="center" bgcolor="#33cc00" style="font-weight:bold;color:#ffffff" onMouseMove="changeColor(2)">旅游资讯</td>
<TD align="center" bgcolor="#33cc00" style="font-weight:bold;color:#ffffff" onMouseMove="changeColor(3)">旅游景点</td>
<TD align="center" bgcolor="#33cc00" style="font-weight:bold;color:#ffffff" onMouseMove="changeColor(4)">酒店查询</td>
<TD align="center" bgcolor="#33cc00" style="font-weight:bold;color:#ffffff" onMouseMove="changeColor(5)">联系我们</td>
</tr>
</table>
</body>
</html>运行出来是undefined
<!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><style type="text/css">
<!--
#Layer1 {
position:absolute;
left:3px;
top:7px;
width:451px;
height:35px;
z-index:1;
}
-->
</style>
</head>
<SCRIPT LANGUAGE="JavaScript">
<!--
function changeColor(j){
var arr = document.all("state");
alert(arr.length);
for(var i=0;i <arr.length;i++){ if(i==j-1){
arr[i].style.cssText="font-weight:bold;color:#ffcc00;";
arr[i].style.backgroundColor="#006600";
} else{
arr[i].style.cssText="font-weight:bold;color:#ffffff;";
arr[i].style.backgroundColor="#33cc00";
}
}
}
//-->
</SCRIPT><body>
<table width="437" border="0" cellspacing="0">
<tr>
<TD height="22" align="center" bgcolor="#33cc00" id=state style="font-weight:bold;color:#ffffff;" onMouseMove="changeColor(1)">首页</TD>
<TD align="center" bgcolor="#33cc00" style="font-weight:bold;color:#ffffff" onMouseMove="changeColor(2)">旅游资讯</td>
<TD align="center" bgcolor="#33cc00" style="font-weight:bold;color:#ffffff" onMouseMove="changeColor(3)">旅游景点</td>
<TD align="center" bgcolor="#33cc00" style="font-weight:bold;color:#ffffff" onMouseMove="changeColor(4)">酒店查询</td>
<TD align="center" bgcolor="#33cc00" style="font-weight:bold;color:#ffffff" onMouseMove="changeColor(5)">联系我们</td>
</tr>
</table>
</body>
</html>运行出来是undefined
解决方案 »
- 怎么在html的<img src="">中调用js变量存储的图片路径?
- Jquery ajax get问题
- 如何实现当单击一小图片时,使其变为另一张小图片(不刷新页面的情况下)在线等候
- top.main.location??
- 新手疑问
- 为什么这段代码可以在ie运行但是在谷歌上没反应
- 我有一个框架(左右两个),我一开始只想看到左边的,但是当我点击一个按扭时,两个才会同时出现,这样怎么实现。。
- javascript如何实现网页下载的进度条功能?
- js中的getAttribute是怎么用 的?
- js上一周下一周和跨月问题
- javascript的客户端判断
- 100分改代码——textarea自由变换(有参考)
<!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> <style type="text/css">
<!--
#Layer1 {
position:absolute;
left:3px;
top:7px;
width:451px;
height:35px;
z-index:1;
}
-->
</style>
</head>
<SCRIPT LANGUAGE="JavaScript">
<!--
function changeColor(j){
var arr = document.all["state"];
alert(arr.length);
for(var i=0;i <arr.length;i++){ if(i==j-1){
arr[i].style.cssText="font-weight:bold;color:#ffcc00;";
arr[i].style.backgroundColor="#006600";
} else{
arr[i].style.cssText="font-weight:bold;color:#ffffff;";
arr[i].style.backgroundColor="#33cc00";
}
}
}
//-->
</SCRIPT> <body>
<table width="437" border="0" cellspacing="0">
<tr>
<TD height="22" align="center" bgcolor="#33cc00" id="state" style="font-weight:bold;color:#ffffff;" onMouseMove="changeColor(1)">首页 </TD>
<TD id="state" align="center" bgcolor="#33cc00" style="font-weight:bold;color:#ffffff" onMouseMove="changeColor(2)">旅游资讯 </td>
<TD id="state" align="center" bgcolor="#33cc00" style="font-weight:bold;color:#ffffff" onMouseMove="changeColor(3)">旅游景点 </td>
<TD id="state" align="center" bgcolor="#33cc00" style="font-weight:bold;color:#ffffff" onMouseMove="changeColor(4)">酒店查询 </td>
<TD id="state" align="center" bgcolor="#33cc00" style="font-weight:bold;color:#ffffff" onMouseMove="changeColor(5)">联系我们 </td>
</tr>
</table>
</body>
</html>
IE6,IE7,IE8,chrome,sarafi3.2,opera9都支持这个属性,但唯独firefox不支持。其他获取元素的方式有:
getElementsByTagName("*") 可以得到得到所有元素的集合
getElemntById 可以按id得到某一元素
getElementsByName 可以得到按name属性得到某一元素如果你的页面对JS加载量没限制,推荐你试用一下jQuery框架,里面的选择器非常实用。
http://jquery.com/