比如说document.forms[0].elements[1].value="";
                                △
这就说名按钮是整个页面的第二个控键
但是现在我想返过来
也就是说我想在点击这个按钮的时候取得这个"1"
应该怎么写啊?

解决方案 »

  1.   

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    <head>
    <title> New Document </title>
    <meta name="Generator" content="EditPlus">
    <meta name="Author" content="">
    <meta name="Keywords" content="">
    <meta name="Description" content="">
    </head>
    <body>
    <form name="demo">
    <input type="button" name="field" value="0" />
    <input type="button" name="field" value="1" />
    <input type="button" name="field" value="2" />
    </form>
    <script language="javascript">
    var Eles = document.forms[0].elements;
    for (var i=0;i<Eles.length;i++){
    Eles[i].setAttribute("Index",i);
    Eles[i].attachEvent("onclick",getSrcElement);
    }
    function getSrcElement(){
    alert(window.event.srcElement.Index);
    }
    </script>
    </body>
    </html>