<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>如何获取事件触发源(兼容IE和FireFox)</title>
<meta name="generator" content="editplus" />
<meta name="author" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<script type="text/javascript">
function ClickMe(e)
{
var src = e.target || window.event.srcElement;
alert(src.value);
alert(src.innerHTML);
}
function ClickMe2()
{
var e = arguments[0] || window.event;
var src = e.srcElement || e.target; // src 就是事件的触发源
alert(src.value);
}
</script>
</head>
<body>
<button onclick="ClickMe(event)">测试</button>
<button onclick="ClickMe2(event)">测试2</button>
</body>
</html>
< script language = " javascript " >
document.onclick = onClick; // 当用户在文档中点击是调用onClick function()
function onClick(ev){
ev = ev || window.event; // 事件
var target = ev.target || ev.srcElement; // 获得事件源
/*
target.getAttribute()是获取该事件源对像里面的一些属性。
比如对像中有(name,id,type等等);
*/
var dragObj = target.getAttribute('type');
alert(dragObj);
}
</ script >