代码如下:
<!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
解决方案 »
- uploadify插件实现在弹出对话框中,在IE中测试一直报“对象不支持此属性和方法”,但是在火狐和遨游却可以完成实现,未报错。
- 请您写出一段html/js代码, 实现下面的页面功能
- 请教下 JS 去除 checkbox 已选勾的问题
- JS问高手这样能实现么?
- 依然是js问题,js给li添加父级元素 如何循环下
- 用window.open()新打开一个窗口,如何使窗口一打开就最大化???
- 关于NS邮件和新闻处理器中邮件规则文件的位置
- 求解:
- 高手帮忙呀,急急。在线等待!!!!!!
- 怎样用java脚本实现 asp中 request类似的作用?? 100相送!
- 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/