zoukankan      html  css  js  c++  java
  • js中如何判断按钮是否被点击了

    firfox版:

    <HTML>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <HEAD>
    <TITLE></TITLE>
    <script>
    document.onclick=function(e){
    var evt=e||window.event;
    var tar=evt.target||evt.srcElement;
    if( (tar.tagName.toLowerCase()=="input"&&tar.type=="button") || tar.tagName.toLowerCase()=="button"){
    alert("你点击的是一个按钮")
    }
    }
    </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>

    google 浏览器版:

    <HTML>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <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>

  • 相关阅读:
    ExtJs-学习篇(1)
    js中的Ajax经典示例
    软件工程开发流程
    Maven和Ajax
    搭建SSH框架
    拦截器
    OGNL
    Struts 2配置详解
    Struts 2入门
    HQL连接查询和注解
  • 原文地址:https://www.cnblogs.com/xmphoenix/p/2108123.html
Copyright © 2011-2022 走看看