gpt4 book ai didi

jQuery 函数有时不运行

转载 作者:行者123 更新时间:2023-12-01 00:33:00 24 4
gpt4 key购买 nike

我有以下函数,主要用于将 iframe 高度设置为其内容的高度:

$("#MSOPageViewerWebPart_WebPartWPQ1").load(function()
{
var Height = document.getElementById('MSOPageViewerWebPart_WebPartWPQ1').contentWindow.document.body.scrollHeight;

document.getElementById('MSOPageViewerWebPart_WebPartWPQ1').height = Height;
});

绝大多数情况下,它都会按预期运行,但在奇怪的情况下,需要多次重新加载页面才能正常运行。当然,尝试调试它是徒劳的,因为它似乎总是能达到功能并工作。

有人知道为什么它可能每次都不起作用吗?

最佳答案

试试这个:

$(function(){
$("#MSOPageViewerWebPart_WebPartWPQ1").load(function()
{
setTimeout(function(){
var Height = document.getElementById('MSOPageViewerWebPart_WebPartWPQ1').contentWindow.document.body.scrollHeight;

document.getElementById('MSOPageViewerWebPart_WebPartWPQ1').height = Height;
});
},100);
});

关于jQuery 函数有时不运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5807186/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com