• boostrap ajax表单验证提交


    ===============================================================================

    1.

    1
    <link href="<%=basePath %>bootstrap/css/bootstrap-datetimepicker.min.css" rel="external nofollow" rel="stylesheet" media="screen">

    ===============================================================================

    $(function(){/* 文档加载,执行一个函数*/
    // $(".submit_review").attr({"disabled":"disabled"});
     $('#defaultForm').bootstrapValidator({
        message: 'This value is not valid',
        feedbackIcons: {/*输入框不同状态,显示图片的样式*/
         valid: 'glyphicon glyphicon-ok',
         invalid: 'glyphicon glyphicon-remove',
         validating: 'glyphicon glyphicon-refresh'
        },
        fields: {/*验证*/
         company_name: {/*键名username和input name值对应*/
          validators: {
           notEmpty: {/*非空提示*/
            message: '公司名称不能为空'
           },
    //       stringLength: {/*长度提示*/
    //        min: 6,
    //        max: 30,
    //        message: '用户名在6到30之间'
    //       }/*最后一个没有逗号*/
          }
         },
         company_id: {
          validators: {
           notEmpty: {
            message: '公司ID不能为空'
           },
          }
         },
         equipment_ip: {
          validators: {
           notEmpty: {
            message: '设备IP不能为空'
           },
           regexp: {
            regexp: /^(d{1,2}|1dd|2[0-4]d|25[0-5]).(d{1,2}|1dd|2[0-4]d|25[0-5]).(d{1,2}|1dd|2[0-4]d|25[0-5]).(d{1,2}|1dd|2[0-4]d|25[0-5])$/,
            message: '设备IP不合法'
             }
          }
         },
        }
      })
     });

    ===============================================================================

     
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    $("#btn_reset").click(function(event) {
      /* Act on the event */
      $('#defaultForm').data('bootstrapValidator').resetForm(true);
     });
     $("body").on('click', '#btn_submit_add', function(event) {
      /* Act on the event */
      $('#defaultForm').bootstrapValidator('validate');
      var flag = $("#defaultForm").data('bootstrapValidator').isValid();
      if (!flag) {
       toastr.error("填写有误,请重新填写!");
      } else {
       $.post('addEquipmentInfoCheck.action', {
        "equipmentInfoCheck.companyId": $("#company_id").val(),
        "equipmentInfoCheck.companyName": $("#company_name").val(),
        "equipmentInfoCheck.machineRoom": $("#computer_room").val(),
        "equipmentInfoCheck.equipmentCabinet": $("#cabinet").val(),
        "equipmentInfoCheck.deviceType": $("#equipment_type").val(),
        "equipmentInfoCheck.deviceName": $("#equipment_name").val(),
        "equipmentInfoCheck.deviceIp": $("#equipment_ip").val(),
        "equipmentInfoCheck.deviceBrand": $("#equipment_brand").val(),
        "equipmentInfoCheck.deviceModel": $("#equipment_model").val(),
        "equipmentInfoCheck.position": $("#shelf_position").val(),
        "equipmentInfoCheck.deviceSn": $("#equipment_sn").val(),
        "equipmentInfoCheck.devicePn": $("#equipment_pn").val(),
        "equipmentInfoCheck.state":1
       }, function(data, textStatus, xhr) {
        /*optional stuff to do after success */
        if (textStatus == "success") {
         // e.preventDefault();
         $('#defaultForm').data('bootstrapValidator').resetForm(true);
         $("#myModal_add").modal('hide');
         toastr.success("提交成功");
        }else{
         $("#myModal_add").modal('hide');
         toastr.error("提交失败");
        }
       });
      }
     });
  • 相关阅读:
    iis 站点部署后 Microsof .Net Framework异常
    数据库中GUID的生成
    影响世界的100个经典管理定律
    帕金森定律(Parkinson's Law)
    eclipse 弹出智能提示、代码自动换行
    eclipse 快捷键
    extjs grid 分页
    extjs gride 显示序号
    SharePoint 2013 Deploy Master Page And Page Layout
    正则表达式匹配并替换字符串
  • 原文地址:https://www.cnblogs.com/vip-deng-vip/p/7856257.html
Copyright © 2020-2023  润新知