按Enter键时将光标移动到下一个文本字段 [英] Move Cursor to next text Field when press Enter
本文介绍了按Enter键时将光标移动到下一个文本字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的脚本文件。当按下Enter键时,我在这个脚本中调用我的div id =AppContainer。这个代码只在chrome浏览器上工作,但不能在其他浏览器中工作。什么问题?
HTML:
< div id =AppContainer>
< input type =text>
< input type =text>
< / div>
< script type ='text / javascript'>
$(document).ready(function(){
$('#AppContainer input')。keydown(function(e){
if(e.keyCode == 13){$ b'b
if($(':input:eq('+($(':input')。index(this)+ 1)+')')。attr('type')=='提交'){//检查提交按钮并在输入时提交表单按
返回true;
}
$(':input:eq('+($(' :input')。index(this)+ 1)+')')。focus();
return false;
}
});
});
< / script>
解决方案
您可以试试这个:
$ b $($'$ p$ $ $ $ $ $'$'$ $ $ $'$'$'$'$'$'$'$' ();
(this).next('input:text')。
}
});
});
This is my script file. I am call my div id="AppContainer " in this script when press enter.This code is working on only chrome browser but not working in other browser.What is the problem?
HTML:
<div id="AppContainer">
<input type="text">
<input type="text">
</div>
<script type='text/javascript'>
$(document).ready(function(){
$('#AppContainer input').keydown(function(e){
if(e.keyCode==13){
if($(':input:eq(' + ($(':input').index(this) + 1) + ')').attr('type')=='submit'){// check for submit button and submit form on enter press
return true;
}
$(':input:eq(' + ($(':input').index(this) + 1) + ')').focus();
return false;
}
});
});
</script>
解决方案
You may try this:
$(function () {
$('#AppContainer').on('keydown', 'input:text', function (e) {
if (13 === e.which) {
e.stopPropagation();
$(this).next('input:text').focus();
}
});
});
这篇关于按Enter键时将光标移动到下一个文本字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文