js代码

<script>
$(function () {
 $("#msg_img").hide();
 $('#registerForm').bind('valid.form', function () {  //当所有表单输入项都校验通过后执行回调函数
 
     $("#btn_submit").attr('disabled', true); //设置提交按钮为不可点击状态 防止重复提交
  //表单对象的serialize方法可以直接将表单数据封装成json数据发送
     $.post("/travel/registUserServlet", $(this).serialize(), function (data) {  //post方式进行异步提交 并且可以接收返回的数据
       
         //处理服务器响应的数据  
         if (data.flag) {
             //注册成功,跳转成功页面
             location.href = "register_ok.html";
         } else {
             //注册失败,给errorMsg添加提示信息
             $("#btn_submit").attr('disabled', false); //设置提交按钮可点击
             $("#msg").html(data.errorMsg);
        }
     });
 });
});
</script>

html表单

<form id="registerForm" autocomplete="off"
                  data-validator-option="{theme:'yellow_right_effect',stopOnError:true}"
            >

 <input id="btn_submit" type="submit" value="提交">
</form>