在我的工作过程中,我尝试通过按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