昨天在论坛求来一个弹出层的效果,但是发现在层上面加上选项卡之后,当点击选项卡的时候弹出层就消失了。我想要的效果是,点击按钮弹出一个层,然后层上面有选项卡,可以点击选项卡切换内容,再点击按钮或者页面其他地方隐藏选项卡页面里有多个这种按钮
昨天的帖子地址http://topic.csdn.net/u/20120719/12/1bec4a8a-c379-45a6-9793-24694f22a610.html?11699
我加上tab选项卡后的代码如下
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>测试</title>
</head>
<body marginwidth="0" marginheight="0" leftmargin="0" topmargin="0" style="background-color: transparent;" onclick="menuHide();">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>&nbsp;</td>
    <td height="400">&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>
<div id="face" style="position: absolute; display: none; width: 319px; height: 213px; background: green;">
<div id="tabCot_product" class="tab">
<div class="tabContainer">
<ul class="tabHead" id="tabCot_product-li-currentBtn-">
<li class="currentBtn"><a href="javascript:void(0)" rel="1">tab1</a></li>
<li><a href="javascript:void(0)" rel="2">tab2</a></li>
</ul>
</div>
<div id="tabCot_product_1" class="tabCot">
 <div class="tnet">111</div>
</div>
<div id="tabCot_product_2" class="tabCot" style="display: none;">
 <div class="tnet">2222</div>
</div>
</div><script type="text/javascript" language="jscript">
function tab(o, s, cb, ev){//tab切换类
var $ = function(o){return document.getElementById(o)};
var css = o.split((s||'_'));
if(css.length!=4)return;
this.event = ev || 'onclick';
o = $(o);
if(o){
this.ITEM = [];
o.id = css[0];
var item = o.getElementsByTagName(css[1]);
var j=1;
for(var i=0;i<item.length;i++){
if(item[i].className.indexOf(css[2])>=0 || item[i].className.indexOf(css[3])>=0){
if(item[i].className == css[2])o['cur'] = item[i];
item[i].callBack = cb||function(){};
item[i]['css'] = css;
item[i]['link'] = o;
this.ITEM[j] = item[i];
item[i]['Index'] = j++;
item[i][this.event] = this.ACTIVE;
}
}
return o;
}
}
tab.prototype = {
ACTIVE:function(){
var $ = function(o){return document.getElementById(o)};
this['link']['cur'].className = this['css'][3];
this.className = this['css'][2];
try{
$(this['link']['id']+'_'+this['link']['cur']['Index']).style.display = 'none';
$(this['link']['id']+'_'+this['Index']).style.display = 'block';
}catch(e){}
this.callBack.call(this);
this['link']['cur'] = this;
}
}
new tab('tabCot_product-li-currentBtn-', '-');
</script> </div>


<div id="face2" style="position: absolute; display: none; width: 319px; height: 213px; background: green;">software group qq群:58156559<br><br><br>弹出层22222</div>
<input type="button" value="^_^1" onClick="showFace(this,'')"><span style="width: 300px;"></span>
<input type="button" value="^_^2" onClick="showFace(this,'2')">
<script>
function showFace(evnet,p2){
  var _top=0,_left=0;
    var _op=evnet;
    while(_op!=null){
        _top+=_op.offsetTop;
        _left+=_op.offsetLeft;
        _op=_op.offsetParent;
    }
    document.getElementById('face'+p2).style.top=_top-213;
    document.getElementById('face'+p2).style.left=_left;
if(p2=='2'){
    document.getElementById('face').style.display='none';
}else{
    document.getElementById('face2').style.display='none';
}
document.getElementById('face'+p2).style.display=document.getElementById('face'+p2).style.display=="block"?'none':'block';}
function hideFace(){
  document.getElementById('face').style.display="none";
  document.getElementById('face2').style.display="none";
}
document.onclick=function (){
  if((document.getElementById('face').style.display=="block" ||  document.getElementById('face2').style.display=="block")
  && event.srcElement.tagName !='INPUT'
  && event.srcElement.tagName !='DIV'){
  document.getElementById('face').style.display="none";
  document.getElementById('face2').style.display="none";
  }
}
</script>


</td>
    <td>&nbsp;</td>
  </tr>
</table>
</body>
</html>

解决方案 »

  1.   

    使用extjs  非常容易实现
      

  2.   

    document.onclick=function (){
      if((document.getElementById('face').style.display=="block" || document.getElementById('face2').style.display=="block")
      && event.srcElement.tagName !='INPUT'
      && event.srcElement.tagName !='DIV'
      && event.srcElement.tagName !='A'){
      document.getElementById('face').style.display="none";
      document.getElementById('face2').style.display="none";
      }
    }加个判断   这里也就是 你想让什么控件点击了不关闭就加上那个判断  这里你是不想让a标签点击了不关闭,所以加个a标签的判断。如果说你不想点击span让其关闭,就再加个判断&& event.srcElement.tagName !='SPAN'  就可以了、、、、、要灵活运用啊。
    不懂的再问。