<!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>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title></title>
<style type="text/css"></style> <script type="text/javascript"> function P()
{
alert(event.srcElement.tagName);
// 这个是发生事件时候,获取鼠标指向的对象.例如:<INPUT>。 如何才能获取被绑定事件对象 <DIV> 呢?
// 就是说我在按钮控件上点击,获取真正被绑定事件的对象(DIV)。怎么做到? this 不行啊。this在IE中是window对象。
}
</script>
</head>
<body><div onclick="P()" id="my1" style="width:200px;height:100px;border:1px solid red;background:#eee" > <input type="button" value="Button" /></div>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title></title>
<style type="text/css"></style> <script type="text/javascript"> function P()
{
alert(event.srcElement.tagName);
// 这个是发生事件时候,获取鼠标指向的对象.例如:<INPUT>。 如何才能获取被绑定事件对象 <DIV> 呢?
// 就是说我在按钮控件上点击,获取真正被绑定事件的对象(DIV)。怎么做到? this 不行啊。this在IE中是window对象。
}
</script>
</head>
<body><div onclick="P()" id="my1" style="width:200px;height:100px;border:1px solid red;background:#eee" > <input type="button" value="Button" /></div>
</body>
</html>
解决方案 »
- 求助 GOOGLE MAP API3 中清除图标太慢、、有没有更好的方法。。
- 求解iframe的问题,高手们请进来看看啊,急!
- js和java交互的问题
- js onmousedown 怎么判断点击的对象
- [连续向下滚动]为啥给tab.scrollTop赋值了,但提示又不是所赋值的值呢!
- 看似简单难死我了:包含框架的IE窗口如何在关闭时自动打开另外一个新窗口?
- 高分请教,在线等
- 在NETSCAPE上怎么实现透明层?
- 如何获取js动态添加的元素进行操作?
- easyui 怎么监听 layout 的收缩和展开事件?
- 《JavaScript权威指南》例子,请教。
- Extjs grid 如何新增或修改排序方法。
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title> </title>
<style type="text/css"> </style>
<script type="text/javascript">
function P()
{
var obj = event.srcElement;
var funName = arguments.callee.toString().match(/^function\s*(\w+\(\))/i)[1];
while(obj && obj.onclick == null && obj.getAttribute("onclick") == null ){
obj = obj.parentNode;
}
if(obj.onclick == arguments.callee|| obj.getAttribute("onclick") == funName){
alert(obj.tagName);
}else{
alert("没找到");
}
// 这个是发生事件时候,获取鼠标指向的对象.例如: <INPUT>。 如何才能获取被绑定事件对象 <DIV> 呢?
// 就是说我在按钮控件上点击,获取真正被绑定事件的对象(DIV)。怎么做到? this 不行啊。this在IE中是window对象。
}
window.onload = function(){
document.getElementById("my2").onclick = P;
};
</script>
</head>
<body> <div onclick="P()" id="my1" style="width:200px;height:100px;border:1px solid red;background:#eee" >
<input type="button" value="Button" />
</div> <div id="my2" style="width:200px;height:100px;border:1px solid red;background:#eee" >
<input type="button" value="Button" />
</div>
</body>
</html>