使用JQuery获取TD的值 [英] To get a value of a TD using JQuery
本文介绍了使用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.
这篇关于使用JQuery获取TD的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文