巧用iframe 和div遮挡 select 等控件

Div被Select挡住,是一个比较常见的问题。有的朋友通过把div的内容放入iframe或object里来解决。
这样会破坏页面的结构,互动性不大好。

另一种方法是:
虽说div直接盖不住select,但是div可以盖iframe,而iframe可以盖select,所以把一个iframe来当作div的底。
相关代码:

  1. <p class="msg">已添加,您现在还需要继续吗?</p>
  2. <p><input name="close" οnclick="javascript:hidePop();" type="button" class="btn1"/></p>
  3. <iframe id="popiframe" style="display:none"></iframe>
  1. function usershowPop()
  2. {
  3.     var width  = 319;  //弹出框的宽度
  4.     var height = 138;  //弹出框的高度
  5.     var obj    = document.getElementById("msg");
  6.     var obj_iframe  = document.getElementById("popiframe");
  7.     
  8.     obj_iframe.style.display  = obj.style.display  = "block";
  9.     obj_iframe.style.position = obj.style.position = "absolute";
  10.     obj_iframe.style.zindex   = obj.style.zindex   = "999";
  11.     obj_iframe.style.width    = obj.style.width    = width + "px";
  12.     obj_iframe.style.height   = obj.style.height   = height + "px";
  13.     
  14.     
  15.     var p_top    = document.documentElement.scrollTop;
  16.     var p_left   = document.documentElement.scrollLeft;
  17.     var p_height = document.documentElement.clientHeight;
  18.     var p_width  = document.documentElement.clientWidth;
  19.      
  20.     leftadd = (p_width-width)/2;
  21.     topadd  = (p_height-height)/2;
  22.     obj_iframe.style.top  = obj.style.top  = (p_top  + topadd)  + "px";
  23.     obj_iframe.style.left = obj.style.left = (p_left + leftadd) + "px";
  24.     
  25.     
  26.     window.onscroll = function (){
  27.         obj_iframe.style.top  = obj.style.top  = (document.documentElement.scrollTop  + topadd)  +"px";
  28.         obj_iframe.style.left = obj.style.left = (document.documentElement.scrollLeft + leftadd) +"px";
  29.     };
  30. }
  31. function userhidePop()
  32. {
  33.     obj = document.getElementById("msg");
  34.     document.body.removeChild(obj);
  35.     document.getElementById("popiframe").style.display = "none";
  36. }

这个div就可以盖住select了.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值