我正在尝试创建一个函数,当按下 Enter 键时,会选择下一个带有类的输入。
我已经设法 .focus() 同一行中的下一个元素。但是,如果我需要在下一行选择下一个输入,则无法继续。
需要关注下一行中的第一个 .quantity 文本框。
控制台没有错误。
HTML
<table>
<tr>
<td>
<input class='quantity' value=''/>
<input class='100' value=''/>
</td>
<td>
<input class='quantity' value=''/>
<input class='50' value=''/>
</td>
<td>
<input class='quantity' value=''/>
<input class='20' value=''/>
</td>
</tr>
<tr>
<td>
<input class='quantity' value=''/>
<input class='100' value=''/>
</td>
<td>
<input class='quantity' value=''/>
<input class='50' value=''/>
</td>
<td>
<input class='quantity' value=''/>
<input class='20' value=''/>
</td>
</tr>
</table>
jQuery
$(".quantity").on('keypress', function (e) {
if (e.keyCode === 13) {
$(this).parent().next('td').find('input.quantity').focus();
}
});