[英]How to find parent table for the row
I have a complex html file. 我有一个复杂的html文件。 I want to select a input[type=text] previous to the table when table row is clicked.
我想在单击表格行时选择表格前面的输入[type = text]。
A html snippet goes here 一个html片段就在这里
<input type=text/>
<table>
<tr>
...
</tr>
</table>
$('tr').click(function() {
$(this).closest('table').prev(input[type=text]).val();
});
This throws 这引发了
`Uncaught TypeError: Object #<HTMLTableRowElement> has no method`closest
How to write jQuery selector to select the input when table row is clicked? 如何编写jQuery选择器以在单击表行时选择输入?
$(this).parent('table').prev('input[type="text"]').val()
OR 要么
$(table).on('click', 'tr', function () {
$(this).[prev/siblings/closest]('input[type="text"]').val();
});
$(this).parents('table')[0].prev(input[type=text]).val();
should do it. 应该这样做。
你可以试试parent()
$(this).parent('table').prev(input[type=text]).val();
Here you have a living demo: http://jsfiddle.net/ceETY/2/ 在这里你有一个生动的演示: http : //jsfiddle.net/ceETY/2/
You can use this: 你可以用这个:
$(this).parent('table').prev('input:text').val();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.