b[0].name
你没有命名,所以找不到名称.
返回为undefined

解决方案 »

  1.   

    没有命名?我不知道,
    我想知道是b[0]而不是b[1],这样我想取b[0]的值
      

  2.   

    <script>
    function x() {
      var el = event.srcElement;
      tag = document.all[el.id];
      for(i=0;i<tag.length;i++) {
        if(el == tag[i])
          alert(i);
      }
    }
    </script>
    <input  id=b type="text" onclick="x()">
    <input  id=b type="text" onclick="x()">
      

  3.   

    把this当成一个参数传进去
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>无标题文档</title>
    <script>
    function f(t){
     alert(t.id);
    }
    </script>
    </head><body>
    <input type="text" id="bb" onClick="f(this);">
    </body>
    </html>
      

  4.   

    <script>
    function x() {
    var a = document.getElementsByTagName("input");
    var b = event.srcElement;
    for(i=0; i<a.length; i++) {
     if(b == a[i])
     alert(i+1);
    }
    }
    </script><form onClick="x()">
    <input type="text" id="bb">
    <input type="text" id="bb">
    <input type="text" id="bb">
    <input type="text" id="bb">
    </form>
      

  5.   

    <input  id=b type="text" onclick="x()">
    <input  id=b type="text" onclick="x()">
    <input  id=b type="text" onclick="x()">
    <input  id=b type="text" onclick="x()">
    ...
    <script>
    function x(){
      var e = event.srcElement;
      if(!e.i){ for(i=0;i<b.length;i++){ b[i].i="b"+i } }
      alert(e.i);
    }
    </script>