在我的工作過程中,我嘗試通過按Enter鍵將焦點從一個文本字段移至另一個文本字段。我已經找到了可能的答案在下面的鏈接:如何將光標移動到下一個文本字段?
How to go to next textbox when enter is pressed?
Move Cursor to next text Field pressing Enter
但都未爲我工作。我的代碼:
<script>
$('input[type='text']').keyup(function(e) {
if(e.keyCode == 13) {
$(this).next().focus();
}
});
</script>
<input type='text' />
<input type='text' />
<input type='text' />
<input type='text' />
<input type='text' />
<input type='text' />
關於您的實際問題在 - 它與服務器端無關。您所做的完全是客戶端,並通過將腳本標記移動到輸入下方進行修復。 –
你爲什麼要用enter?從字面上看,沒有人會期望這種行爲。 – Slime
@Waxi你是對的。使用Enter來進入下一個輸入將是無用的,因爲沒有人會使用它。切換輸入焦點的默認鍵是** Tab鍵**,其工作不需要javascript – Aloso