使用JQuery获取TD的值
问题描述:
我有一个非常简单的表,只有两行.
我在想从ID为"row2"的TD获取值的最佳方法是什么.
I got a very simple Table with only two rows.
I was thinking what is the best way to get the value from the TD with ID "row2".
<Table id="testing>
<tr>
<th>
</th>
<td id="row1">hello</td>
</tr>
<tr>
<th>
</th>
<td id="row2">world</td>
</tr>
</table>
这是我的尝试:
Here is my attempt:
$(document).ready(function(){
var r=$("#testing":row2).val();
alert(r);
});
但是我看不到任何消息弹出.
如果要同时指定Table ID和TD ID,该怎么办?
But I couldn't see any message pop up.
What shall I do in the JQuery code if I want to specify the Table ID along with the TD ID?
var r=$("#testing":row2).text();
var r=$("#testing").children("row2").text();
答
这将为您做到:
var r = $("#testing #row2").text();
alert(r);
在这里发挥作用,以吸引您的观看乐趣.
In action here for your viewing pleasure.