在firefox下实现如下功能的javascript的写法
我有网页有21个 <div id= "simg "> </div>
我想写一个程序一次将它们填进 某一个值.
以下方法在IE里能运行,但是在firefox里无法运行.也没有提示错误,
for(i=0;i <=20;i++) {
simg[i].innerHTML= " ";
}
请帮忙.
------解决方案-------------------- <!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>
function doFunction(){
var divArray = document.getElementsByTagName( "div ");
for(var i = 0 ;i < divArray.length;i++){
divArray[i].innerHTML = " ";
}
}
</SCRIPT>
</head>
<body onclick= "doFunction() ">
<form name= "frm ">
<div id= "simg "> fdsafdsa </div>
<div id= "simg "> fdsafdsa </div>
<div id= "simg "> fdsafdsa </div>
<div id= "simg "> fdsafdsa </div>
<div id= "simg "> fdsafdsa </div>
<div id= "simg "> fdsafdsa </div>
<div id= "simg "> fdsafdsa </div>
<div id= "simg "> fdsafdsa </div>
<div id= "simg "> fdsafdsa </div>
<div id= "simg "> fdsafdsa </div>
</body>
</html>
------解决方案--------------------- -b
狂汗用id做循环
建议不要使用id作循环了,用name来做循环
id和name的区别,id是唯一的和身份证一样,不能重复,重复了就出错
name就和姓名一样,用来叫得么,不过还是有很多人重名的么