我有一張表,我想在下一行的td中插入html。 我粘貼在下面一行。jquery插入html不起作用
<tr class="content">
<td align="center">
<a class="version" href="theurl">click here to update the td in the row below</a>
</td>
<td align="left">col 2</td>
<td align="left">col 3</td>
<td align="left">col 4</td>
<td align="left">col 5</td>
<td align="left">col 6</td>
</tr>
<tr class="version" style="display: none;">
<td colspan="6"></td> <-- this is where i want to insert the new html in.
</tr>
我的jQuery腳本看起來像這樣。
$("a.version").click(function() {
var sLink = $(this).attr("href"); <-- this gets the link to retrieve data from
var nexttr = $(this).parent().parent().next(".version"); <-- gets the next tr
var nexttrtd = $(this).parent().parent().next(".version td:first"); <-- gets the first td in the next tr. alerting the colspan displays 6 (which is correct)
nexttrtd.html("hello world"); <-- this wont insert the text in the td.
nexttr.css("display", "");
return false;
});
現在的問題是,爲什麼HTML不顯示在TD?我試過append,innerHTML =「bla」,那也行不通。
認爲我正在按照手冊做事,但無法真正弄清楚它出錯的地方。
有什麼想法?
別忘了'nexttr.show();'「hello world」後放入td – munch 2010-01-09 18:11:50
謝謝!我放入了冗餘代碼以確保我獲得了正確的元素。但是使用.find鏈接nexttr可以完成所有工作。 它也解決了我寫的第二個問題(。html) – 2010-01-09 18:49:00
@半個書呆子,如果它解決了你的問題,不要忘記標記答案爲接受:) – 2010-01-09 19:21:16