Jquery 为什么我的的内容高度不断增加?
以下是调用它的函数:Jquery 为什么我的的内容高度不断增加?,jquery,Jquery,以下是调用它的函数: $("#iFrame").load(function () { resizeIframe(); }); // on load resize is called loadIFrame(url); //this loads url in i frame function resizeIframe() { var iFHeight = $('iFrame').contents().height(); var iFWidth = $('iFrame').co
$("#iFrame").load(function () { resizeIframe(); }); // on load resize is called
loadIFrame(url); //this loads url in i frame
function resizeIframe() {
var iFHeight = $('iFrame').contents().height();
var iFWidth = $('iFrame').contents().width();
$("#content").css("height", iFHeight);
$("#content").css("width", iFWidth);
}
如果第一次加载内容的iFrame高度为100px,则第二次加载内容的iFrame高度为200px。内容的第三次加载高度再次为100px,但仍停留在200px。为什么不改变高度?即使高度现在是100像素?试试这个
$('iframe').load(function(){
var $body = $(this).contents().find('body');
$("#content").css({
height: $body.height(),
width: $body.width()
});
})
.attr('src', 'iframeUrlHere');
您能在中重现问题吗?包括content元素的HTML以及调用该函数的代码。我认为问题在于您的iframe中有不同的内容,或者contenxt第一次没有完全加载。什么时候调用resizeIframe?我添加了调用方法的方式。我添加了调用resizeIframe函数的方式。在加载i帧时调用它。你现在能看一下吗?你的上述答案对我来说不起作用,否则我将不得不重写所有内容。