rt

解决方案 »

  1.   

    层外跟隐藏层是什么关系?能说具体点吗 ,最好有html代码
      

  2.   

    回1楼:
    <form>
    ...
    <div id='div1'>
    <div>
    ...
    </from>
    ...部分代表div1层外  层外发生鼠标单击事件则隐藏div1 层内单击则不隐藏
      

  3.   

    請樓主試試<!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=utf-8" />
    <title>无标题文档</title>
    <style>
    #div1{ width:100px; height:100px; background:#f00;}
    </style>
    <script>
    window.onload = function(){
        var isOut = true;
        var dom = document.getElementById('div1');
        var other = window.document;
        other.onclick = function(){
            if(isOut){
                dom.style.display = 'none';
            }
             isOut = true;
        }
        dom.onclick = function(){
            isOut = false;
            this.style.display = 'block';
        }
    }
    </script>
    </head>
    <body>點擊(除div本身外)的任何地方關閉div1<br><div id="div1">我是div1</div>
    </body>
    </html>
      

  4.   

    哦,對不起!沒注意樓主你要的是支持jquery,呵呵...
      

  5.   

    jquery代码:$(function(){
    $("#div2").click(function(){
      $("#div1").hide();//隐藏id=div1的内部div 
    });
    });<div id="div2" style="width:100px;height:100px;border:1px solid red;margin:1px;">
    <div id='div1' style="width:50px;height:50px;border:1px solid blue;margin:1px">
    div1
    <div>
    </div>
      

  6.   

    $("#div").on("click",function(){
        return false;//阻止冒泡
    });
    $(document).on("click",function(){
        $("#div").hide();
    });