gpt4 book ai didi

javascript - 如何将光标移动到下一个文本字段?

转载 作者:行者123 更新时间:2023-12-01 03:51:08 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com