假设我有一个JS变量和我的HTML数据存储到它像通过jquery的确定高度和动态HTML元素的宽度
var data = '<div id="tst">here will be my othere html</div>'
在这种情况下我能确定什么会是高度& DIV的宽度使用jQuery的tst?
一个人给我的解决方案就像
var $test = $(data).appendTo('body');
var size;
window.setTimeout(function(){
size = {
height: $test.height(),
width: $test.width()
};
$test.remove();
});
,但上面的代码看起来有点复杂。如果有人知道简单的解决方案,那么请给我一个示例代码来这样做。感谢
你不需要使用'.setTimeOut()'。 –