0
在下面的代碼中,我試圖讓字符串(40*(parseInt($('#2-cat').attr('id')))+1)
爲移動div的像素高度。但它不工作,我真的不明白爲什麼 - 我已經放了兩個其他測試代碼行,服務器似乎接受這個字符串是一個整數...但它不想讓我把它用於div的高度。無法使用整數字符串作爲像素值?
$(document).ready(function() {
$('p').click(function(){
//$('p').html(40*(parseInt($('#2-cat').attr('id')))+5)
//$("#line").animate({"top":"80px"});
$("#line").animate({"top":"(40*(parseInt($('#2-cat').attr('id')))+1)px"});
});
});
HTML:
<div id='line' style='height:100px; width:100px; background-color:red;position:relative'></div>
<div id='2-cat'>hello</div>
<p>hellos</p>
所有可以在http://jsfiddle.net/platypus117/XyLNG/1/
你可以在隨機的地方扔這樣的Javascript代碼嗎? – 2011-12-14 15:43:51