2013-02-28 48 views
0

我試圖做一個計算,但我不斷得到錯誤NaN; 你能幫我解決var testBottom的數學問題嗎?jQuery計算給NaN

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); 
}); 
+0

嘗試parseInt函數(testTop)+ parseInt函數(testHeight); – Satya 2013-02-28 15:24:32

+0

歡迎來到StackOverflow :) – jbabey 2013-02-28 15:29:13

+0

什麼價值越來越testTop&testHeight? – 2013-02-28 15:29:39

回答

3

test.offset();返回與topleft性質,而不是一個號碼的對象。如果您需要頂部偏移量,則需要向下鑽取:

var testTopOffset = test.offset().top; 

請參閱documentation

+0

非常感謝。你是最棒的! – PatrickH 2013-02-28 15:28:00

1
var testTopOffset = test.offset(); 

應該是

var testTopOffset = test.offset().top 
+0

謝謝你的回答,和jbabey一樣! – PatrickH 2013-02-28 15:31:30