新聞資訊
來源:成都網站建設 作者:賽維思網絡 發布日期:2014-05-06 瀏覽:1970次
小編最近在排版時發現iframe框架中的表單超過其框架高度后不知道應該怎么被自動隱藏,相信也有其他朋友同樣遇到過這種問題,那么我們就一起來探究下應該怎樣實現這個問題吧,以下是小編經過千辛萬苦(有點夸大了啊,嘻嘻)才找到的一個解決方法:
<script type="text/javascript">
$(document).ready(function()
{
// Set specific variable to represent all iframe tags.
var iFrames = document.getElementsByTagName_r('iframe');
// Resize heights.
function iResize()
{
// Iterate through all iframes in the page.
for (var i = 0, j = iFrames.length; i < j; i++)
{
// Set inline style to equal the body height of the iframed content.
iFrames[i].style.height = iFrames[i].contentWindow.document.body.offsetHeight + 'px';
}
}
// Check if browser is Safari or Opera.
if ($.browser.safari || $.browser.opera)
{
// Start timer when loaded.
$('iframe').load(function()
{
setTimeout(iResize, 0);
}
);
// Safari and Opera need a kick-start.
for (var i = 0, j = iFrames.length; i < j; i++)
{
var iSource = iFrames[i].src;
iFrames[i].src = '';
iFrames[i].src = iSource;
}
}
else
{
// For other good browsers.
$('iframe').load(function()
{
// Set inline style to equal the body height of the iframed content.
if(this.contentWindow.document.body.offsetHeight>1000)
{
this.style.height = 700 + 'px';//此處為最小高度的設置
}else{
this.style.height = this.contentWindow.document.body.offsetHeight + 'px';
}
}
);
}
}
);
</script>
看的懂么?哈哈,其實也不用看懂,只要把上述文件外加一個jquery文件一起加載下,你會發現你想要的效果已經出現了...
Copyright ? www.yrgym.cn All Rights Reserved. 成都賽維思網絡技術有限公司 蜀ICP備13002520號-3 Sitemap