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>
event代表事件的状态,例如触发event对象的元素、鼠标的位置及状态、按下的键等等。
event对象只在事件发生的过程中才有效。
event的某些属性只对特定的事件有意义。比如,fromElement 和 toElement 属性只对 onmouseover 和 onmouseout 事件有意义