gpt4 book ai didi

javascript - jQuery.html( something ) 检测注入(inject)何时完成

转载 作者:数据小太阳 更新时间:2023-10-29 05:27:10 26 4
gpt4 key购买 nike

简而言之,我希望在注入(inject) html 并呈现该 html 的内容后触发回调。原因是我需要立即知道新内容的高度。像这样:

  $('div').html(tonsofstuff);
console.log( $('div').height() ); //works in Firefox, but returns 0 in Chrome
setTimeout(function(){
console.log( $('div').height() ); //works everywhere, but takes too long
},3000);

这个问题偶尔会出现在某些浏览器中(并且总是在 chrome 中)$('div').height() 在新内容具有高度之前触发。

我的幻想:

  $('div').html(tonsofstuff, function(){
console.log( $('div').height() );
});

or even

$('div').html(tonsofstuff).load(function(){
console.log( $('div').height() );
});

最佳答案

这是我的做法:

var height = $('div').html(tonsofstuff).height();

我在等待它渲染时从未遇到过任何问题。

关于javascript - jQuery.html( something ) 检测注入(inject)何时完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8945957/

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