zoukankan      html  css  js  c++  java
  • JS 实现点击页面任意位置隐藏div、span

    通过调用下面的 showhidden(“标签ID”) 显示div/span/…等标签内容,可以实现点击页面任意地方再次隐藏该标签内容,而showhidden(“标签ID”,”nohidden”)可保存显示不隐藏。可用于仿下拉框及下拉菜单的实现。

    var nowshowdiv="";
    function showhidden(div,nohidden){
             if(div!=""){
                       if(document.getElementById(div).style.display==""&&nohidden!="nohidden"){
                                document.getElementById(div).style.display="none";
                                nowshowdiv="";
                       /*当nohidden的值为 nohidden 时,div的状态保持为显示状态*/
                       }else if(nohidden=="nohidden"){
                                nowshowdiv="";
                                setTimeout("nowshowdiv='"+div+"'",500);
                       }else{
                                document.getElementById(div).style.display="";
                                setTimeout("nowshowdiv='"+div+"'",500);
                       }
             }else{
                       if(document.getElementById(nowshowdiv)){
    document.getElementById(nowshowdiv).style.display="none"; nowshowdiv=""; } } } document.onclick=function(){ showhidden(""); }
  • 相关阅读:
    3.27上午
    3.24上午 补
    2017.3.27下午
    2017.3.27上午
    2017.3.24下午
    2017.3.24上午
    2017.3.23下午
    2017.3.23上午
    2017.3.22上午
    2017.3.21下午
  • 原文地址:https://www.cnblogs.com/programs/p/5493829.html
Copyright © 2011-2022 走看看