在我的工作中,我尝试通过按 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' />
最佳答案
$(document).ready(function () {
$('form').on('submit', function (event) {
event.preventDefault();
})
$('input[type="text"]').keyup(function(event) {
if(event.keyCode === 13) {
$(this).next().focus();
}
});
})
<script src="https://code.jquery.com/jquery-3.2.1.slim.js"></script>
<form>
<input type="text"/>
<input type="text"/>
<input type="text"/>
<input type="text"/>
<input type="text"/>
</form>
关于javascript - 如何将光标移动到下一个文本字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43192252/