<form name="tablename">
<input type="text" name="price[]" onKeyUp="count_price(this);">
<input type="text" name="price[]" onKeyUp="count_price(this);">
<input type="text" name="price[]" onKeyUp="count_price(this);">
</form>
<script>function count_price(obj)
{
    var a=document.getElementsByName(obj.name);
    for(var i=0; i<a.length; i++)
    {
        if(a[i]==obj)
        {
            alert("index:"+ i);
            break;
        }
    }
}
</script>

解决方案 »

  1.   

    <form name="tablename" ID=Form1>
    <input type="text" name="price" onKeyUp="count_price(this);" ID=Text1>
    <input type="text" name="price" onKeyUp="count_price(this);" ID=Text2>
    <input type="text" name="price]" onKeyUp="count_price(this);" ID=Text3>
    </form>
    <script>function count_price(obj)
    { var objlen=document.getElementsByName("price").length;
     for(var i=0;i<objlen;i++)
     {
      if(document.getElementsByName("price")[i].id==obj.id)
      {
      alert(i);
      }
     }
    }</script></body>
      

  2.   

    <form name="tablename" ID=Form1>
    <input type="text" name="price[]" onKeyUp="count_price(this);" ID=Text1>
    <input type="text" name="price[]" onKeyUp="count_price(this);" ID=Text2>
    <input type="text" name="price[]" onKeyUp="count_price(this);" ID=Text3>
    </form>
    <script>function count_price(obj)
    { var objlen=document.getElementsByName("price[]").length;
     for(var i=0;i<objlen;i++)
     {
      if(document.getElementsByName("price[]")[i].id==obj.id)
      {
      alert(i);
      }
     }
    }</script></body>