初学js 怎么能够比较快速得到一组html元素的ID?? 当然可以啦,getElementById 里面放的是字符串,是字符串的话就可以进行字符串的运算,然后把结果再传给 getElementById 的。如果这样不行的话,那就太傻了 ^_^ 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 但是结果只能返回第一个元素?? getElementById()的参数好像不可以是变量吧?谢谢回复!下面是我试验的代码:<html><head><title>tempory</title><script type="text/javascript">var i;function showvalue(){for(i=0; i<4; i++){ document.writeln(document.getElementById("id"+i).value);}} </script></head><body><div class="input"><form id="form"><input class="box" type="text" id="id0" value="" /><input class="box" type="text" id="id1" value="" /><input class="box" type="text" id="id2" value="" /><input class="box" type="text" id="id3" value="" /><input class="box" type="button" id="response" value="response" onclick="showvalue();" /></form></div></body></html> <html> <head> <title>tempory </title> <script type="text/javascript"> function showvalue(){ var outStr=""; for(var i=0;i<4;i++) { outStr = outStr + document.getElementById("id"+i).value + "<br>" } document.writeln(outStr);} </script> </head> <body> <div class="input"> <form id="form"> <input class="box" type="text" id="id0" value="" /> <input class="box" type="text" id="id1" value="" /> <input class="box" type="text" id="id2" value="" /> <input class="box" type="text" id="id3" value="" /> <input class="box" type="button" id="response" value="response" onclick="showvalue();" /> </form> </div> </body> </html> LZ例子中的document.write(ln)把当前滴文档清空所以document.getElementById就什么都获取不到喽看看LS滴例子把或者alert好了 <script type="text/javascript"> var i; function showvalue(){ for(i=0; i <4; i++) { document.writeln(document.getElementById("id"+i).value); } } </script> 原来的文档被丢弃了。。没循环一次,丢弃一次。最后答案就是一个。 不可能的,你这个document.writeln执行过一次,画面上的元素都没了,document.getElementById("id"+i).value这个怎么可能取得到值,既然你的答案只有一个,直接写成document.writeln(document.getElementById("id3").value)不就行了吗?还这么麻烦干嘛。 明白了,document.write() 之后,页面就改变了。 js如何调用vb的dll? 一个字体问题,能说原因会能定义出这个字体的样式的直接给分100 高手酒馆!!!! extjs 右键菜单 问题 对了,在框架页面怎么样屏蔽F11, Ctrl+n等 如何使得点击iframe页面中的submit按钮后。。。。 关于修改注册表的问题:怎样在网页中调用控件时不出现提示 请问个降低耦合的问题,很简单的,请大家帮帮忙,急急急急急急急!!!!! 怎样得到当前网页的源文件?要没有任何改动的。 如何识别图片上的数字 高分求JavaScript 参考手册 用js如何对名称为变量的下拉列表框赋值?
下面是我试验的代码:
<html>
<head><title>tempory</title>
<script type="text/javascript">var i;
function showvalue(){
for(i=0; i<4; i++)
{
document.writeln(document.getElementById("id"+i).value);
}
}
</script>
</head>
<body>
<div class="input">
<form id="form">
<input class="box" type="text" id="id0" value="" />
<input class="box" type="text" id="id1" value="" />
<input class="box" type="text" id="id2" value="" />
<input class="box" type="text" id="id3" value="" />
<input class="box" type="button" id="response" value="response" onclick="showvalue();" />
</form>
</div></body>
</html>
<html>
<head> <title>tempory </title>
<script type="text/javascript">
function showvalue(){
var outStr="";
for(var i=0;i<4;i++)
{
outStr = outStr + document.getElementById("id"+i).value + "<br>"
}
document.writeln(outStr);
} </script>
</head>
<body>
<div class="input">
<form id="form">
<input class="box" type="text" id="id0" value="" />
<input class="box" type="text" id="id1" value="" />
<input class="box" type="text" id="id2" value="" />
<input class="box" type="text" id="id3" value="" />
<input class="box" type="button" id="response" value="response" onclick="showvalue();" />
</form>
</div> </body>
</html>
把当前滴文档清空
所以document.getElementById
就什么都获取不到喽看看LS滴例子把
或者alert好了
function showvalue(){
for(i=0; i <4; i++)
{
document.writeln(document.getElementById("id"+i).value);
}
} </script> 原来的文档被丢弃了。。没循环一次,丢弃一次。最后答案就是一个。