表单的提交问题

表单提交时如果不做其他操作会默认提交到后台对应的方法中,但我们可以通过js来屏蔽掉他的默认提交从而方便我们在前台做判断。但有个前提是我们在返回前必须写上return false;

 

@using (Html.BeginForm())

{

}

            $("form").submit(function (form) {

                var Mobile = $("#Mobile").val();

                if (Mobile == "") {

                    alerts("手机号码格不能为空!");

                    return false;

                }

                if (!/^1[3,4,5,8][0-9]{9}$/.test(Mobile)) {

                    alerts("你输入的手机号码格式不正确!");

                    return false;

                } else {

                    $.ajax({

                        type: ‘post‘,

                        url: ‘/UserOperation/Create/‘,

                        data: $("form").serialize(),

                        success: function (result) {

                            if (result == "OK") {

                                if (confirm("操作员绑定成功!")) {

                                    location.href = "/UserOperation/Index?UMType=" + QueryString(location.search, "UMType");

                                }

                            } else {

                                alerts(result);

                            }

                        }

                    });

                    return false;

                }

            });

表单的提交问题

上一篇:Pat(Advanced Level)Practice--1047(Student List for Course)


下一篇:(转)怎样理解阻塞非阻塞与同步异步的区别?