不好意思,刚才发错了,应当如下:
<html>
<head>
        <script Language = "javascript">        
            function qq()
            {
              alert('div');
              arguments[0].stopPropagation();
            }
        </script>
    </head>
    <body onclick = "alert('body')">
        <div id="div1" onclick ="qq()" style="width:100px;height:100px;background-color:red">test for test</div>
    </body>
</html>

解决方案 »

  1.   


    这个是没错的啊,一次点击同时触发了BODY与DIV上的ONCLICK的事件不太明白你想说什么,如果说要要控制事件的触发,你可以自己定义一个开关来实现嘛。
      

  2.   

    arguments[0].stopPropagation();
    这个就是用来控制向上冒泡的可是不管用啊?
      

  3.   

    你的onclick="qq()"里,要传递一个参数,like this
    <html>
    <head>
            <script Language = "javascript">        
                function qq()
                {
                  alert('div');
                  arguments[0].stopPropagation();
                }
            </script>
        </head>
        <body onclick = "alert('body')">
            <div id="div1" onclick ="qq(event)" style="width:100px;height:100px;background-color:red">test for test</div>
        </body>
    </html>
      

  4.   

    阻止冒泡在firefox和ie下是不同的
    <!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>
           <script Language = "javascript">        
                function qq(event)
                {
            var event=window.event||event
                  alert('div');
          if(arguments[0].stopPropagation)
                  event.stopPropagation();
              else
          event.cancelBubble=true;    
                }
            </script>
        </head>
        <body onclick = "alert('body')">
            <div id="div1" onclick ="qq(event)" style="width:100px;height:100px;background-color:red">test for test</div>
        </body>
    </html>
      

  5.   


    5楼正解。学习了,谢谢。cancelBubble在IE下有效 
    stopPropagation在Firefox下有效http://heimuad.javaeye.com/blog/125001