div等待條

來源:互聯網
上載者:User

 

一直使用div做的等待狀態條,保證使用者在提交之後不能進行操作,但是發現此方法存在問題:div無法遮蓋頁面中的“select”元素,如果使用者在提交過程中更改select元素的選中項,會導致提交之後的結果不正確。

google一下,發現有一種可以使用iframe結合ie的過濾器解決此問題的方法:

iframe來當作div的底
<html>
<head>
<script>
function DivSetVisible(state)
{
var DivRef = document.getElementById('PopupDiv');
var IfrRef = document.getElementById('DivShim');
if(state)
{
DivRef.style.display = "block";
IfrRef.style.width = DivRef.offsetWidth;
IfrRef.style.height = DivRef.offsetHeight;
IfrRef.style.top = DivRef.style.top;
IfrRef.style.left = DivRef.style.left;
IfrRef.style.zIndex = DivRef.style.zIndex - 1;
IfrRef.style.display = "block";
}
else
{
DivRef.style.display = "none";
IfrRef.style.display = "none";
}
}
</script>
</head>
<body>
<form>
<select>
<option>A Select Box is Born ....</option>
</select>
</form>
<div id="PopupDiv" style="position:absolute; top:25px; left:50px; padding:4px; display:none; background-color:#000000; color:#ffffff; z-index:100">
.... and a DIV can cover it up<br/>through the help of an IFRAME.
</div>
<iframe id="DivShim" src="javascript:false;" scrolling="no" frameborder="0" style="position:absolute; top:0px; left:0px; display:none;">
</iframe>
<br/>
<br/>
<a href="#" onclick="DivSetVisible(true)">Click to show DIV.</a>
<br/>
<br/>
<a href="#" onclick="DivSetVisible(false)">Click to hide DIV.</a>
</body>
</html>

另外一種方法,可以在提交頁面顯示div的時候,將select元素隱藏。

var selectEles = document.getElementsByTagName("select");

if(selectEles == null || selectEles.length == 0) {

    return;

}

for(var i=0; ; i++) {

    if(i = selectEles.length) break;

    selectEles[i].style.display = "none";

}

說明:由於頁面展現使用jsf,因此頁面中無法使用">","<","&&"等符號,因此使用其它方法繞開此問題。

本文從本人其他部落格搬家而來,當時感覺還是不錯的,只是在這個技術日新的今天,不知道還合適不合適,歡迎拍磚

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.