新手 求教一个事件 的父子继承关系的问题 事件响应顺序 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 或者也可以判断事件源<!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><script type="text/javascript">function init(){ document.getElementsByTagName('div')[0].onclick=function(e){ var a=e||window.event; var t=a.srcElement||a.target; alert(t.innerHTML); }}window.onload=init;</script></head><body><div> <p>abcdefg</p> <br/> <p>pppp</p></div></body></html>类似这样试试 <div onclick="fun('div',event)"> <p onclick="fun('p111',event)">abcdefg</p> <br/> <p onclick="fun('p222',event)">pppp</p></div><script type="text/javascript"> function fun(str,e){ e = e || window.event; e.stopPropagation ? e.stopPropagation() : e.cancelBubble = true;//阻止冒泡 alert(str); }</script> 点p后,p的click事件先发生,外层div的click事件后发生---这就是事件的冒泡。要想让div的click无效,需要阻止事件冒泡,即:在p的click事件函数中加上组织冒泡的方法(3楼所示),这样事件就不会继续传递了~事件冒泡~网上资料很多 这些双引号怎么理解啊? 求一个效果!在线等。谢谢各位!!!!!!!!!!!!!! firefox下,如何让 textarea中的内容自动换行? 关于IE下的内存回收研究. 紧急求助,关于层控制问题。 公用的js验证 我想取9.936小数位的两位小数94 并判断它是否被25整除 怎么写代码?用JavaSript 像我这种要求,框架嵌套合适吗? 怎么写一个类似提示框的东西。 两个IP是否能够ping通的条件? 开始,学习javascript ajax提交form表单,到底怎么做?急死了。用button按钮提交,不是submit
<!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>
<script type="text/javascript">
function init(){
document.getElementsByTagName('div')[0].onclick=function(e){
var a=e||window.event;
var t=a.srcElement||a.target;
alert(t.innerHTML);
}
}
window.onload=init;
</script>
</head><body>
<div>
<p>abcdefg</p>
<br/>
<p>pppp</p>
</div>
</body>
</html>
类似这样试试
<p onclick="fun('p111',event)">abcdefg</p>
<br/>
<p onclick="fun('p222',event)">pppp</p>
</div>
<script type="text/javascript">
function fun(str,e){
e = e || window.event;
e.stopPropagation ? e.stopPropagation() : e.cancelBubble = true;//阻止冒泡
alert(str);
}
</script>
要想让div的click无效,需要阻止事件冒泡,即:在p的click事件函数中加上组织冒泡的方法(3楼所示),这样事件就不会继续传递了~事件冒泡~网上资料很多