0

我试图进行计算,但我不断收到错误 NaN;你能帮我弄清楚如何为 var testBottom 做数学吗?

jQuery(document).ready(function(){
var test = jQuery("#test");
var testTopOffset = test.offset();
var testTop = testTopOffset;
var testHeight = test.height();
var testBottom = parseInt(testTop + testHeight);
alert(testHeight);
alert(testBottom);
});
4

2 回答 2

3

test.offset();返回具有topleft属性的对象,而不是数字。如果您想要顶部偏移量,则需要向下钻取:

var testTopOffset = test.offset().top;

请参阅文档

于 2013-02-28T15:25:04.750 回答
1
var testTopOffset = test.offset();

应该

var testTopOffset = test.offset().top
于 2013-02-28T15:25:12.427 回答