layui checkbox 提交多個值的解決方法【轉】


數據是從后台來的

<div class="layui-form-item" >
     <label class="layui-form-label">品種</label>
     <div class="layui-input-inline">
          {foreach $quotation_type as $key=>$val}
               <input name="quotation_type" lay-skin="primary" value="{$key}" title="{$val}" type="checkbox">
          {/foreach}
      </div>
</div>

看看JS部分,有點繞,先把數據寫進數組,然后,數組轉成json格式,覆蓋掉原先的data.field里面的數據

//獲取checkbox數據
quotation = new Array();
$("input:checkbox[name='quotation_type']:checked").each(function(){
     quotation.push($(this).val());
});
var json = {};
for (var i = 0; i < quotation.length; i++) {
     json[i] = quotation[i];
}
let myJson = JSON.stringify(json);
data.field.quotation_type =  myJson ;

PHP部分,只需要把提交過來的json字符串轉成數組就可以使用了

//提交的checkbox   提交過來的是json字符串
$data['quotation_type'] = json_decode($request->post('quotation_type'),true);

最后,進行你需要的數據庫操作就可以了
文章轉自:https://blog.csdn.net/Gino_tkzzz/article/details/84315622


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM