假设我有这样的东西:
<tr>
<td><input type="text" /></td>
<td>Somevalue</td>
<td><intput type="text /></td>
</tr>
我正在处理第一个文本框的按键事件。如果存在,我想使用jQuery查找下一个具有文本框的td。
<tr>
<td><input type="text" /></td>
<td>Somevalue</td>
<td><intput type="text /></td>
</tr>
我正在处理第一个文本框的按键事件。如果存在,我想使用jQuery查找下一个具有文本框的td。
这样类似的代码应该可以正常工作(假设this
是输入)。
var next = $(this).parent().next("td > input[type='text']");
tj111的答案对我不起作用。 可能是因为jQuery的新版本。我想到了这个:
var next = $(this).parent().nextAll().has("input[type='text']").first();
我不知道你的选择器是什么,但如果你需要选择所有输入(文本类型),你可以尝试这个。
$(function(){
$(':input').each(function(){
$(this).keypress(function(){
$(this).next('input[type=text]').val('I\'m the next');
}) // end of keypress
}) // enf of each
}) // End of function
所以,无论您放置更多的输入在哪里,您总是可以获取它们。