TITLE> New Document </TITLE>
<script>
function test(){
var objs=document.all.t1
for(i=0;i<objs.length;i++)
{
var obj=objs[i];//这样能得到每个t1对象
// alert(obj.value)
}
// 请问使用什么API可以对象,在所有t1中的位置,例如:现在我想获得位置3
}
</script>
</HEAD>
<BODY>
<input type="input" name="t1" value="a">
<input type="input" name="t1" value="b">
<input type="input" name="t1" value="c" onclick="this">
<input type="input" name="t2" value="d">
<input type="input" name="t3" value="e">
<input type="input" name="t1" value="f">
<input type="input" name="t1" value="g">
<input type="button" value="测试" onclick="test()">
</BODY>
</HTML>

解决方案 »

  1.   

    document.getElementsByName("t1")[2].value
      

  2.   

    可以用if(obj==obj)的方式来判断是不是同一个对象
      

  3.   

    请问在javascript中,能倒推出来,对象所在对象数组中得数组位置.
      

  4.   


    <HTML>
    <HEAD>
    <TITLE> New Document </TITLE>
    <script>
    function test(obj){
      var objs=document.getElementsByName("t1")
      for(var i=0;i<objs.length;i++){
        if(objs[i]==obj)
        return i
      }
    }
    </script>
    </HEAD>
    <BODY>
    <input type="input" name="t1" value="a">
    <input type="input" name="t1" value="b">
    <input type="input" name="t1" value="c" onclick="alert(test(this))">
    <input type="input" name="t2" value="d">
    <input type="input" name="t3" value="e">
    <input type="input" name="t1" value="f">
    <input type="input" name="t1" value="g">
    </BODY>
    </HTML>