我想創建一個函數,當按Enter鍵發生下一個類的輸入被選中。Jquery專注於下一個元素與類
我已成功將.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();
}
});
您有多個'quantity'文本框。下一行的哪個「數量」文本框應該有重點? –
第一。對不起,我會修改問題。我正在尋找模擬tabindex。 – goingsideways