zoukankan      html  css  js  c++  java
  • JS点击其他区域隐藏——应用级

    http://www.uw3c.com/jsviews/js57.html

    <div id="sbt">search</div>
    <div id="search" style="display: block;">点击其他区域隐藏</div>
    <script type="text/javascript">
        $(function(){
            $("#sbt").click(function(e){
                $("#search").show();
                var ev = e || window.event;
                if(ev.stopPropagation){
                    ev.stopPropagation();
                }
                else if(window.event){
                    window.event.cancelBubble = true;//兼容IE
                }
            })
            document.onclick = function(){
                $("#search").hide();
            }
            $("#search").click(function(e){
                var ev = e || window.event;
                if(ev.stopPropagation){
                    ev.stopPropagation();
                }
                else if(window.event){
                    window.event.cancelBubble = true;//兼容IE
                }
            })
        })
    </script>

     上面的程序IE11有时间不灵改了一下的写的方式

    $(document).bind('click',function(){
                    $('#test').css('display','none');
                });

    完整如下;

    <script type="text/javascript">
                function stopPropagation(e) {
                    if (e.stopPropagation) 
                        e.stopPropagation();
                    else 
                        e.cancelBubble = true;
                }
    
                $(document).bind('click',function(){
                    $('#test').css('display','none');
                });
    
                $('#test').bind('click',function(e){
                    stopPropagation(e);
                });
            </script>

    链接:http://www.cnblogs.com/dolphinX/p/3239530.html

  • 相关阅读:
    单元测试
    软件测试计划
    软件杯A9的设计与实现
    阅读笔记7
    阅读笔记6
    阅读笔记5
    阅读笔记4
    阅读笔记3
    阅读笔记2
    阅读笔记1
  • 原文地址:https://www.cnblogs.com/dlgood/p/6549014.html
Copyright © 2011-2022 走看看