<SCRIPT LANGUAGE="JavaScript">
<!--
function cc(obj)
{
var b = document.activeElement;
var aa = document.getElementsByName("a");
for(var i= 0;i<aa.length;i++)
{
if(aa[i]==b)
{
alert(i);
break;
}
}
}
//-->
</SCRIPT>
<input type=text name="a">
<input type=text name="a" >
<input type=text name="a">
<input type=text name="a"><SCRIPT LANGUAGE="JavaScript">
<!--
document.onclick = cc;
//-->
</SCRIPT>

解决方案 »

  1.   

    可以为input自定义一个属性:
    <style>
    input{t:expression(this.onclick=function(){alert(this.xuhao)})}
    </style>
    <body>
    <input type=text name="a" xuhao='1'>
    <input type=text name="a" xuhao='2'>
    <input type=text name="a" xuhao='3'>
    <input type=text name="a" xuhao='4'>
    </body>也可以使用input已有的属性:
    <style>
    input{t:expression(this.onclick=function(){alert(this.id)})}
    </style>
    <body>
    <input type=text name="a" id='1'>
    <input type=text name="a" id='2'>
    <input type=text name="a" id='3'>
    <input type=text name="a" id='4'>
    </body>也可以查找所有的input:
    <style>
    input{t:expression(this.onclick=function(){get(this)})}
    </style>
    <script>
    function get(obj)
    {
      var d=document.getElementsByTagName('input');
      for(var i=0;i<d.length;i++)
       {
         if(d[i]==obj)
           {alert((i+1).toString());break;}
       }
    }
    </script>
    <body>
    <div>
    <input type=text name="a">
    <input type=text name="a">
    <input type=text name="a">
    <input type=text name="a">
    </div>
    </body>