var len = document.forms[0].elements.length;
for(var i=0;i<len;i++){
  alert(i);
}

解决方案 »

  1.   

    var theInput = document.getElementById( theInputID )
    var theObjs = document.forms[0].getElementsByTagName( "INPUT" );
    for( i = 0 ; i < theObjs.length ; i++  )
    {
        if( theObjs[ i ] == theInput )
        {
             alert( i )
        }
    }
      

  2.   

    我的意思是如何确定一个input是form里的索引
    to xishanlang2001(西山狼2000):因为form里有很多的input,如果都循环的话可能会影响速度,有没有办法不做循环或者做少量循环得到input的索引号
      

  3.   

    html本身不提供,只好初始化一下
    var theObjs = document.forms[0].getElementsByTagName( "INPUT" );
    for( i = 0 ; i < theObjs.length ; i++  )
      theObjs[ i ].indexID = i;以后就可以用indexID得到了
    一次循环总可以吧