<script language=javascript> function getValue() { //请问 ? 这个值要如何获得 document.form1.t2[?].value='aaa'; //我想实现的效果是当我点击t1[0]时,t2[0]返回相应的值,以上代码则变成: document.form1.t2[0].value='aaa'; //问题是?这个值要如何用document.getElementsById获得。 } </script> <form name=form1> 编号 <input type = text name = t1 onclick="getValue()"> 名称 <input type = text name = t2>
编号 <input type = text name = t1 onclick="getValue()"> 名称 <input type = text name = t2> ...... </form>
<script>function getValue(obj){
var t1s=document.getElementsByName("t1");
var t2s=document.getElementsByName("t2");
for(var i=0;i<t1s.length;i++){
if(t1s[i]==obj)obj.value=t2s[i].value;
}
}
</script> <form name=form1>
编号 <input type = text name ="t1" onclick="getValue(this)"/> 名称 <input type = text name ="t2"/> <br />
编号 <input type = text name ="t1" type="button" onclick="getValue(this)"/> 名称 <input type = text name ="t2"/> <br />
编号 <input type = text name ="t1" type="button" onclick="getValue(this)"/> 名称 <input type = text name ="t2"/> <br /></form>