我有一张表,我想在下一行的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