JS遍历HTML元素最好给html数组加上id属性,然后使⽤document.all来进⾏遍历
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<SCRIPT type="text/javascript">
var objs = document.all['url'];
for(var i=0; i<objs.length; i++){
window.alert(objs[i].value);
}
</SCRIPT>
</head>
<body>
<form name="form1">
<input id = "url"name="url[]" type="text" value="url 1" size="60" />
<inputid = "url"name="url[]" type="text" value="" size="60" />
<input id = "url" name="url[]" type="text" value="url 3" size="60" />
</form>
</body>
</html>
<HTML>
<head>
<SCRIPT LANGUAGE="JavaScript">
/
html document是什么/遍历表格的每⾏每列
function viewCell()
{
var count=1; //在表格中显⽰的内容
for (i=0; i < document.ws.length; i++) { //遍历每⾏
for (j=0; j < document.ws(i).cells.length; j++) { //遍历⾏中的每⼀列 document.ws(i).cells(j).innerText = count; //在单元格显⽰数值
count++;
}
}
alert(count);
}
</SCRIPT>
</head>
<BODY onLoad="viewCell()">
<TABLE id=tbl border=1 width="200">
<TR><TH> </TH><TH> </TH><TH> </TH><TH> </TH></TR>
<TR><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR>
<TR><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR>
</TABLE>
</BODY>
</HTML>

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。