<input type="button" onclick="alert('Push me') />

解决方案 »

  1.   

    开始没说明白我的意思,
    我的意思是,如何在<script type="text/javascript">....<script>中来判断客户端按下的是哪个按钮。最好用IF 之类的语言表述下,谢谢
      

  2.   

    你这个想法最好不用0层事件注册机制,给你的建议是用addEventListener或者用attachEvent注册事件,如果是鼠标点击事件,参数有属性可以判断点击的是什么按钮
      

  3.   

    以下方法适合于任意HTML对象,
    下面判断了一下是否是button
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd"
    <HTML> 
    <HEAD> 
    <TITLE></TITLE> 
    <script>
    document.onclick=function(){
    var obj = event.srcElement;
    if(obj.type == "button"){
    alert(obj.id);
    }
    }
    </script>
    </HEAD> <BODY>
    <input id="button1" type="button" value="1111"/>
    <input id="button2" type="button" value="2222"/>
    <input id="button3" type="button" value="3333"/>
    <input id="button4" type="button" value="4444"/>
    </BODY> 
    </HTML> 
      

  4.   

    document.onclick不会被执行到呀,怎么办?
      

  5.   

    documend.body.onclick=function(){
        var obj = event.srcElement;
        if(obj.type == "button"){
            alert(obj.id);
        }
    }
      

  6.   

    不是documend.onclick与documend.body.onclick的问题
    要把JS放在Body内
      

  7.   

    5楼的firfox里好象不行吧,该怎么写啊