<!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>
解决方案 »
- 邮箱正则表达式, 求解释
- 求大神帮小弟解决下EXTJS 复选框的问题。
- html.replace中的字符问题
- div.InnerHtml如何添加图片?
- 求教,如何实现这种效果?
- 用JAVASCRIPT怎么能得到css中的属性值。
- 我想改变下拉框的按钮和滚动条的颜色,并且把它们变成扁平的形状,行吗?
- document.all.text1.value="您好";这种写法是否规范?会不会对IE的版本有限制?可是一般的书中都是写成document.form1.text1.value="您好"
- 关于网页中图片可以预载的疑问?(图片是否真的可以预载)
- 新手求救!!!!!急,急,急!!!
- 《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>