AutoCAD 3DMAX C语言 Pro/E UG JAVA编程 PHP编程 Maya动画 Matlab应用 Android
Photoshop Word Excel flash VB编程 VC编程 Coreldraw SolidWorks A Designer Unity3D
 首页 > JavaScript

JavaScript判断按钮被点击的方法

51自学网 http://www.wanshiok.com
js判断按钮是否被点击, javascript点击按钮,判断按钮是否被点击

废话不多说了,直接给大家贴代码了。

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> 

以上是小编给大家分享的JavaScript判断按钮被点击的方法,希望大家喜欢。


js判断按钮是否被点击, javascript点击按钮,判断按钮是否被点击  
上一篇:分享Javascript实用方法二  下一篇:jquery插件uploadify实现带进度条的文件批量上传