尝试这个:
HTML:
<div></div>
<button>Button</button>
JS:
$("button").click(function () {
//BEFORE HTML INSERTED, DIV IS EMPTY
var height = $("div").scrollTop($("div"))[0].scrollHeight;
console.log(height); //Outputs 1 (the starting div height)
alert(height);
//Add more <p>TEST4</p> and see that height SCROLLHEIGHT does indeed grow/update.
$("div").html("<p>TEST</p><p>TEST2</p><p>TEST3</p>");
$("div").height(50); // DIV starts at 1PX, and we set to 50PX so that we can see contents.
//AFTER HTML INSERTED
height = $("div").scrollTop($("div"))[0].scrollHeight;
console.log(height); //Outputs 124 (the scroll height, notice the actual div height is 50)
alert(height);
});
jsfiddle