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判断按钮被点击的方法,希望大家喜欢。

声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:notice#nhooo.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。