jquery 回车代替tab

时间:2014-10-01 23:12:52   收藏:0   阅读:575

$(function () {

        //回车代替tab

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

        //如果有其他输入类型可以在此处加入

        var $target = $(‘input,button,select‘);

        $target.bind(‘keydown‘, function (e) {

            var key = e.which;

            if (key == 13) {

                e.preventDefault();

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

                if ($target.eq(nxtIdx).attr("type") == "submit") {

                    $target.eq(nxtIdx).click();

                } else {

                    $target.eq(nxtIdx).focus();

                }

            }

        });

    });


原文:http://my.oschina.net/thinker4self/blog/323778

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!