访问jQuery中的兄弟姐妹 [英] accessing a siblings in jquery
本文介绍了访问jQuery中的兄弟姐妹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码:
<table><tr><td>hello</td>
<td><input type="text" value="0" onkeypress="GetValue();" /></td>
<td><input type="text" value="15" /></td>
</tr>
</table>
<script type="text/javascript">
function GetValue(){
// ???
}
</script>
我如何访问第三个td的值(值为15的td) 不使用简单的方法,并给td一个id并通过使用.parent()或.siblings()来调用它,这是一个简化我的工作的简单示例,但是在我的实际项目中,输入的值与DB绑定在一起而且要获得帮助的情况要复杂得多
how can i access the value of the third td ( the td with the value 15 ) without using the the easy way and give the td an id and call it i want by using .parent() or .siblings() this is a simple example to simplify my work but in my actual project the input have their value binded from DB and it's much more complicated any help apreciated
推荐答案
您可以通过:nth-child()选择器来实现.
You can do it via the :nth-child() selector.
JS代码:
$('table td:nth-child(3) input').val();
这篇关于访问jQuery中的兄弟姐妹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文