最近在做一个页面:功能上想实现点提交按钮的时候,页面变灰(并且无法点击页面元素),同时给出一个提示信息:业务处理中,请稍候。
现在使用DIV实现了页面普通元素的覆盖,但是在IE6下面,无法半透明覆盖下拉表单(看了网上介绍的iframe方法,但是会把页面完全覆盖掉,如果页面由很多下拉表单组成,覆盖后的页面惨不忍睹),在其他浏览器下无法覆盖java.applet生成的页面控件。
求助: 请大虾指点ie 6下如何半透明覆盖下拉表单, 或者能否把iframe整成半透明。 谢谢!
具体代码如下(点按钮'Show Div'能够覆盖页面普通元素,无法覆盖下拉表单):
<style type="text/css">
<!--
html,body {height:100%; margin:0px; font-size:12px;}
.mydiv {
background-color: #f9fff6;
border: 1px solid #009900;
text-align: center;
line-height: 25px;
font-size: 13px;
font-weight: bold;
z-index:99;
width: 300px;
height: 50px;
left:50%;/*FF IE7*/
top:50%;/*FF IE7*/
margin-left:-150px!important;/*FF IE7 half of its width */
margin-top:-60px!important;/*FF IE7 half of its height*/
margin-top:0px;
position:fixed!important;/*FF IE7*/
position:absolute;/*IE6*/
_top: expression(eval(document.compatMode &&
document.compatMode=='CSS1Compat') ?
documentElement.scrollTop + (document.documentElement.clientHeight-this.offsetHeight)/2 :/*IE6*/
document.body.scrollTop + (document.body.clientHeight - this.clientHeight)/2);/*IE5 IE5.5*/
}
.bg {
background-color: #C2BEBF;
width: 100%;
height: 100%;
left:0;
top:0;/*FF IE7*/
filter:alpha(opacity=40);/*IE*/
opacity:0.4;/*FF*/
z-index:1;
position:fixed!important;/*FF IE7*/
position:absolute;/*IE6*/
_top: expression(eval(document.compatMode &&
document.compatMode=='CSS1Compat') ?
documentElement.scrollTop + (document.documentElement.clientHeight-this.offsetHeight)/2 :/*IE6*/
document.body.scrollTop + (document.body.clientHeight - this.clientHeight)/2);/*IE5 IE5.5*/
}
-->
</style>
<script language="javascript" type="text/javascript">
function showDiv(){
document.getElementById('popDiv').style.display='block';
document.getElementById('bg').style.display='block';
}
function closeDiv(){
document.getElementById('popDiv').style.display='none';
document.getElementById('bg').style.display='none';
}
</script>
<div id="popDiv" class="mydiv" style="display:none;">The system is dealing with your request, please waiting...<br/>
<!--<a href="javascript:closeDiv()">close</a>--></div>
<div id="bg" class="bg" style="display:none;">
</div>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>弹出半透明层 (支持IE FF)</title>
</head>
<body>
<form id="frm1" name="frm1" action="new_page_2.htm" method="post">
<input type="button" value="Show DIV" onclick="showDiv()" />
<select><option >test</option></select>
<br><br><br><br>
<select name="selOccPool" multiple="multiple" size="6" style="width:20%" id="selOccPool">
<option value = "**All**" selected="true">**All**</option>
<option value="6A">6A</option>
<option value="6B">6B</option>
<option value="6C">6C</option>
<option value="6D">6D</option>
<option value="6E">6E</option>
<option value="6F">6F</option>
<option value="6G">6G</option>
</select>
</form>
</body>
</html>
问题修改后如下:
<style type="text/css">
<!--
html,body {height:100%; margin:0px; font-size:12px;}
.mydiv {background-color: #f9fff6;
border: 1px solid #009900;
text-align: center;
line-height: 25px;
font-size: 13px;
font-weight: bold;
z-index:99999;
width: 300px;
height: 50px;
left:50%;/*FF IE7*/
top:50%;/*FF IE7*/
margin-left:-150px!important;/*FF IE7 half of its width */
margin-top:-60px!important;/*FF IE7 half of its height*/
margin-top:0px;
position:fixed!important;/*FF IE7*/
position:absolute;/*IE6*/
_top: expression(eval(document.compatMode &&
document.compatMode=='CSS1Compat') ?
documentElement.scrollTop + (document.documentElement.clientHeight-this.offsetHeight)/2 :/*IE6*/
document.body.scrollTop + (document.body.clientHeight - this.clientHeight)/2);/*IE5 IE5.5*/
}
.bg {
background-color: #C2BEBF;
width: 100%;
height: 100%;
left:0;
top:0;/*FF IE7*/
filter:alpha(opacity=40);/*IE*/
opacity:0.4;/*FF*/
z-index:99998;
position:fixed!important;/*FF IE7*/
position:absolute;/*IE6*/
_top: expression(eval(document.compatMode &&
document.compatMode=='CSS1Compat') ?
documentElement.scrollTop + (document.documentElement.clientHeight-this.offsetHeight)/2 :/*IE6*/
document.body.scrollTop + (document.body.clientHeight - this.clientHeight)/2);/*IE5 IE5.5*/
}
.ibg {
position:absolute;
z-index:99997;
filter:alpha(opacity=1);/*IE*/
opacity:.01;/*FF*/
width:expression(document.body.clientWidth);
height:expression(document.body.clientHeight);
}
.s{line-height:15px;}
-->
</style>
<script type="text/javascript">
function Offset(e)
//取标签的绝对位置
{
var t = e.offsetTop;
var l = e.offsetLeft;
var w = e.offsetWidth;
var h = e.offsetHeight-2;
while(e=e.offsetParent)
{
t+=e.offsetTop;
l+=e.offsetLeft;
}
return {
top : t,
left : l,
width : w,
height : h
}
}
function loadSelectDiv(obj){
//第一步:取得Select所在的位置
var offset=Offset(obj);
//第二步:将真的select隐藏
obj.style.display="none";
//第三步:虚拟一个div出来代替select
var iDiv = document.createElement("div");
iDiv.id="selectof" + obj.name;
iDiv.name="selectDiv";
iDiv.style.position = "absolute";
iDiv.style.width=offset.width + "px";
iDiv.style.height=offset.height + "px";
iDiv.style.top=offset.top + "px";
iDiv.style.left=offset.left + "px";
iDiv.style.fontSize="13px";
iDiv.style.lineHeight=offset.height + "px";
iDiv.style.textIndent="4px";
iDiv.style.overflowY="scroll"
iDiv.style.borderRight='#cccccc 1px solid';
iDiv.style.borderTop='#000000 2px solid';
iDiv.style.borderLeft='#000000 2px solid';
iDiv.style.borderBottom='#cccccc 1px solid';
document.body.appendChild(iDiv);
//第四步:将select中的选项显示出来
var tValue='';
for (var i=0;i<obj.options.length;i++){
tValue+="<div class='s'>"+obj.options[i].innerHTML+"</div>";
}
iDiv.innerHTML=tValue;
}
function unloadSelectDiv(obj){
obj.style.display="";
}
function hideSelect(){
if ( /MSIE 6.0/ig.test(navigator.appVersion) ) {
//为ie6
var x=document.getElementsByTagName("select");
for(var i=0;i<x.length;i++){
loadSelectDiv(x[i]);
}
}
}
function removeElement(_element){
var _parentElement = _element.parentNode;
if(_parentElement){
_parentElement.removeChild(_element);
}
}
function showSelect(){
if ( /MSIE 6.0/ig.test(navigator.appVersion) ) {
//为ie6
var x=document.getElementsByTagName("select");
for(var i=0;i<x.length;i++){
unloadSelectDiv(x[i]);
removeElement(document.getElementById("selectof" + x[i].name));
}
}
}
function showDiv(){
hideSelect();
document.getElementById('ibg').style.display='block';
document.getElementById('bg').style.display='block';
document.getElementById('popDiv').style.display='block';
}
function closeDiv(){
showSelect();
document.getElementById('popDiv').style.display='none';
document.getElementById('bg').style.display='none';
document.getElementById('ibg').style.display='none';
}
</script>
<div id="popDiv" class="mydiv" style="display:none;">The system is dealing with your request, please waiting...<br/>
<a href="javascript:closeDiv()">close</a></div>
<div id="ibg" class="ibg" style="display:none " >
<iframe class="ibg" frameborder="0"></iframe>
</div>
<div id="bg" class="bg" style="display:none;">
</div>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>弹出半透明层 (支持IE FF)</title>
</head>
<body>
<form id="frm1" name="frm1" action="new_page_2.htm" method="post">
<input type="button" value="Show DIV" onclick="showDiv()" />
<select><option >test</option></select>
<br><br><br><br>
<select name="selOccPool" multiple="multiple" size="6" style="width:20%" id="selOccPool">
<option value = "**All**" selected="true">**All**</option>
<option value="6A">6A</option>
<option value="6B">6B</option>
<option value="6C">6C</option>
<option value="6D">6D</option>
<option value="6E">6E</option>
<option value="6F">6F</option>
<option value="6G">6G</option>
</select>
</form>
</body>
</html>