首页 > 其他 > 详细

00023-layui表单有check、radio、switch,未选中时值不提交的解决

时间:2020-06-04 23:17:19      阅读:39      评论:0      收藏:0      [点我收藏+]

表单字段:

<div class="layui-form-item layui-form-item-45" >
   <label class="layui-form-label">是否需要外勤</label>
   <div class="layui-input-block">
      <input type="checkbox" name="isNeedOut" lay-filter="form-switch" lay-skin="switch" lay-text="是|否">
   </div>
</div>
<div class="layui-form-item layui-form-item-45" >
   <label class="layui-form-label">是否收费</label>
   <div class="layui-input-block">
      <input type="checkbox" name="isCost" lay-filter="form-switch" lay-skin="switch" lay-text="是|否">
   </div>
</div>
<div class="layui-form-item layui-form-item-45" >
   <label class="layui-form-label">是否延期</label>
   <div class="layui-input-block">
      <input type="checkbox" name="isDelay" lay-filter="form-switch" lay-skin="switch" lay-text="是|否">
   </div>
</div>

提交:

var dialog = layer.open({
             type: 2
             ,title: ‘添加任务单‘
             ,content: ‘../task/taskForm.jsp‘
             ,maxmin: true
             ,area: layui.setter.area
             ,btn: [‘确定‘, ‘取消‘]
             ,btnAlign: ‘c‘
             ,yes: function(index, layero){
                 var iframeWindow = window[‘layui-layer-iframe‘+ index]
                     ,submit = layero.find(‘iframe‘).contents().find("#taskForm-submit");
                 iframeWindow.layui.form.on(‘submit(taskForm-submit)‘, function(data){
                     var field = data.field;
                     field.taskSource = 1;//合同事项
field.isUrgent = field.isUrgent?field.isUrgent:false;
                     field.isNeedOut = field.isNeedOut?field.isNeedOut:false;
                     field.isCost = field.isCost?field.isCost:false;
                     field.isDelay = field.isDelay?field.isDelay:false;
                     var rtn = admin.syncReq(ctx+"/task/task/add",field);
                     if(rtn && rtn.code==0){
                         layer.msg(‘操作成功‘);
                         active.reload();
                         layer.close(index);
                     }else{
                         layer.msg(‘操作失败‘);
                     }
                 });
                 submit.trigger(‘click‘);
             }
         });
         layer.full(dialog)

像这样:

field.isUrgent = field.isUrgent?field.isUrgent:false;

无值是传false 到后台即可。

00023-layui表单有check、radio、switch,未选中时值不提交的解决

原文:https://www.cnblogs.com/jianquan100/p/13046951.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!