jQuery计算给出了NaN

时间:2013-02-28 15:22:49

标签: javascript jquery

我正在尝试进行计算,但我不断得到错误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);
});

2 个答案:

答案 0 :(得分:3)

test.offset();返回一个包含topleft属性的对象,而不是数字。如果你想要向下钻取顶部偏移量:

var testTopOffset = test.offset().top;

请参阅documentation

答案 1 :(得分:1)

var testTopOffset = test.offset();

应该是

var testTopOffset = test.offset().top
相关问题