jquery换行转回车

   <script type="text/javascript">
//        $(document).ready(function () {

//            var allInputs = $(":input");
//            var formChildren = $("form > *");
//            $("#messages").text("Found " + allInputs.length + " inputs and the form has " +
//                             formChildren.length + " children.");

//            // so it won't submit  
//            $("form").submit(function () { return false; });

//        });  
    </script>
    <script type="text/javascript">

                $(function () {
                    $(":input").keypress(function (e) {
                        if (e.which == 13) // 判断所按是否回车键
                        {
                            var inputs = $("body").find(":text"); // 获取表单中的所有输入框
                            var idx = inputs.index(this); // 获取当前焦点输入框所处的位置
                            if (idx == inputs.length - 1) // 判断是否是最后一个输入框
                            {
                                if (confirm("最后一个输入框已经输入,是否提交?")) // 用户确认
                                    $("form[0]").submit(); // 提交表单

                            } else {
                                inputs[idx + 1].focus(); // 设置焦点
                                inputs[idx + 1].select(); // 选中文字
                            }
                            return false; // 取消默认的提交行为
                        }
                    });
                });

        //        $(function () {
        //            $("body").live("keydown", function () {
        //                var x = event.srcElement;
        //                if( x.id != '<%= txtPrize.ClientID %>' )
        //                {
        //                    if (window.event.keyCode == 13) {  //txtPrize
        //                            window.event.keyCode = 9;
        //                        }
        //                    }
        //            })
        //        })
    </script>

posted @ 2011-06-01 01:42  shiningrise  阅读(623)  评论(0编辑  收藏  举报
// 侧边栏目录 // https://blog-static.cnblogs.com/files/douzujun/marvin.nav.my1502.css