2011-10-12 65 views
-1

定義ID,因此這工作得很好,大家都知道jQuery的具有可變

$("#foo").html = "bar"; 

不過,我會怎麼做呢?我也試過$("#"+i),但那也行不通。

回答

6

這不起作用。

$("#foo").html = "bar"; //Overwrites the object's html function with a string 

這應該。

$("#"+i).html("bar"); //Sets the inner HTML of the selected element. 
+0

是的,你'對,我需要括號而不是'='。我把這兩個混在一起了。愚蠢的錯誤。謝謝! – jdborg

2

我不知道你有什麼特林做

但如果你想在插入此值barid='foo'

可以使用

var i = "foo" ; 

    $('#'+i).html("bar");