采用的结构:

<form class="layui-form  reset-form" action="" id="formData">
            @* 使用隐藏域用于保存编辑项的ID值,便于提交修改 *@
            <input type="hidden" name="ID" />
            <div style="color:red;text-align:center;margin-bottom:5px;">注:所填数量不应含省平台转办的信息数量,应仅为本地区自主受理的数量</div>
            <div class="layui-form-item">
                <label class="layui-form-label">日期</label>
                <div class="layui-input-inline">
                    <input name="GetTime" id="date" placeholder="请选择日期范围" autocomplete="off" class="layui-input" type="text">
                    <span class="red required">*</span>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">设区市</label>
                <div class="layui-input-inline">
                    <select name="CityID" lay-verify="required" lay-search="" lay-filter="selectChange"></select>
                    <span class="red required">*</span>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">行政区</label>
                <div class="layui-input-inline">
                    <select name="RegionID" lay-verify="required" lay-search=""></select>
                    <span class="red required">*</span>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">咨询建议当日受理量(个)</label>
                <div class="layui-input-inline">
                    <input name="AmountConsultation" lay-verify="required" autocomplete="off" class="layui-input" type="text" id="DepartmentName" value="">
                    <span class="red required">*</span>
                </div>
            </div>
</form>

提交时:

参数打包  $('#formData').serialize() 但是发现少了 ‘设区市’ 和 ’行政区’

另外:

    .serialize() 方法  通过序列化表单值,创建 URL 编码文本字符串

 1 form.on('submit(save)', function () {
 2                 $('#date').removeAttr('disabled'); 5                 //判断提交路径
 6                 if (pageType == "add") {
 7                     saveUrl = "/ComplaintsSummary/AddComplaintsSummary"
 8                 } else {
 9                     saveUrl = "/ComplaintsSummary/UpdateComplaintsSummary";
10                 }
11                 $.ajax({
12                     url: saveUrl,
13                     type: "post",
14                     data: $('#formData').serialize(),
15                     success: function (res) {
16                         if (res.IsSuccess) {
17                             layer.msg(res.Message, { icon: 1, time: 1000 }, function () {
18                                 parent.layer.closeAll()
19                                 parent.DepartTable.reload()
20
21                             });
22
23                         } else {
24                             layer.msg(res.Message, { icon: 2, time: 1500 })
25                         }
26                         $('#date').attr('disabled', 'true');29                     },
30                     error: function () {
31                         $('#date').attr('disabled', 'true');

34 } 35 }) 36 })

查找原因后发现是因为在修改时因为需求  ‘行政区’和’设区市’

因为不能修改所以设成了禁用状态,但是这样我们在提交时也拿不到了

$('[name=CityID]').attr('disabled', 'true');
$('[name=RegionID]').attr('disabled', 'true');

那么我们在提交时就要在接口之前解除禁用状态

 $('[name=CityID]').removeAttr('disabled');
 $('[name=RegionID]').removeAttr('disabled');

或者

$('[name=CityID]').prop("disabled",false)
$('[name=RegionID]').prop("disabled",false)
02-12 04:21