右键页面空白处,出现div块 ,左键单击其他空白处,div消失问题:右键出现 div ,我单击div区域里面的东西,不会除外外面的左键事件,也就是div不消失,如何改,这个好像是什么冒泡了代码:
<!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 runat="server">
    <title></title>
    <script src="jquery-1.4.4.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            var mouseX;
            var mouseY;
            $(document).bind("contextmenu", function (e) {  //去掉默认右键功能
                return false;
            });                       
            $(document).mousedown(function (e) {
                mouseX = event.clientX;
                mouseY = event.clientY;                
                if (3 == e.which) { //右键单击
                    $("#area").css('margin-left', mouseX);
                    $("#area").css('margin-top', mouseY);
                    $("#area").show();                                     
                } else if (1 == e.which) { //左键单击
                    $("#area").hide();                          
                }
            })        })          
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>      
    <div id="area" style="width:150px; height:200px; background-color:red; display:none;" >
    <input type="button" value="我是按钮" onmousedown="alert('11');" />
    </div>
    </div>
    </form>
</body>
</html>

解决方案 »

  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 runat="server">
        <title></title>
    <script src="http://code.jquery.com/jquery-latest.js"></script>
        <script type="text/javascript">
            $(document).ready(function () {
                var mouseX;
                var mouseY;
                $(document).bind("contextmenu", function (e) {  //去掉默认右键功能
                    return false;
                });                       
                $(document).mousedown(function (e) {
                    mouseX = e.clientX;
                    mouseY = e.clientY;
                    if (3 == e.which) { //右键单击
                        $("#area").css('margin-left', mouseX);
                        $("#area").css('margin-top', mouseY);
                        $("#area").show();                                     
                    } else if (1 == e.which && !( $('#area').find(e.target).length != 0 || $('#area')[0] == $(e.target)[0])) { //左键单击
                        $("#area").hide();                          
                    }
    return
                })        })          
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>      
        <div id="area" style="width:150px; height:200px; background-color:red; display:none;" >
        <input type="button" value="我是按钮" onmousedown="alert('11');" />
        </div>
        </div>
        </form>
    </body>
    </html>参考下