有一段古董代码
var readHtml = '收件人: ' + str + '
';
readHtml += ''
$('#reader').html(readHtml);
我现在想要获取生成文字的宽度,尝试代码如下:
console.log($('#recipients-all').prev());
console.log($('#recipients-all'));
var scorllWidth = $('#recipients-all').prev()[0].offsetWidth + $('#recipients-all')[0].offsetWidth;
console.log(scorllWidth);
console.log($('#reader')[0].offsetWidth);
结果获得的结果全部都是0。
但在浏览器的console中能获取到正确的值。

已经试过$('#reader').ready(function() {}了,并没有好转。
不知道有什么办法能获取到刚插入内容的宽度。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
试试
$('#reader').append($(readHtml));
console.log($('#reader')[0].offsetWidth);