解决方案 »

  1.   

    或者也可以判断事件源
    <!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>
    类似这样试试
      

  2.   

    <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>
      

  3.   

    点p后,p的click事件先发生,外层div的click事件后发生---这就是事件的冒泡。
    要想让div的click无效,需要阻止事件冒泡,即:在p的click事件函数中加上组织冒泡的方法(3楼所示),这样事件就不会继续传递了~事件冒泡~网上资料很多