春与秋
春有百花秋有月,夏有凉风冬有雪;若无闲事挂心头,便是人间好时节。
春与秋
当前位置: 首页 > PHP > 正文

使用Jquery实现回车键Enter切换焦点等同于tab

在IE,Firefox,Chrome上测试通过。


<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.3/jquery.min.js" type="text/javascript"></script>
<div>

<input type="text" ID="tb1" class="cls" /><br />

<input type="text" ID="tb2" class="cls" /><br />

<input type="text" ID="tb3" TextMode="MultiLine" class="cls" /><br />

<input type="text" ID="tb4" class="cls" /><br />

</div>

<script type="text/javascript">

$(function () {

$('input:text:first').focus();

var $inp = $('.cls');

$inp.bind('keydown', function (e) {

var key = e.which;

if (key == 13) {

e.preventDefault();

var nxtIdx = $inp.index(this) + 1;

$(".cls:eq(" + nxtIdx + ")").focus();

}

});

});

</script>

您可能还会对这些文章感兴趣!

使用Jquery实现回车键Enter切换焦点等同于tab:等您坐沙发呢!

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

gravatar

? razz sad evil ! smile oops grin eek shock ??? cool lol mad twisted roll wink idea arrow neutral cry mrgreen