通过调用下面的 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(""); }

 

posted on 2016-05-14 22:54  老松壳  阅读(9865)  评论(0编辑  收藏  举报