在Laravel 5.1中无法发布复选框的值 [英] In Laravel 5.1 Can't post value of checkbox
本文介绍了在Laravel 5.1中无法发布复选框的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在表单中有2个复选框,我无法发布它们的值. 我已经尝试过了:
I have 2 checkboxs inside a form, I can't post value of them. I have already tried this:
<div class="form-group col-md-4">
<label class="col-md-6" for="invoiced">
<input type="checkbox" id="invoiced" value="false" name="project[invoiced]">
Invoiced </label>
<label class="col-md-6" for="tobeinvoiced">
<input type="checkbox" id="tobeinvoiced" value="true" name="project[tobeinvoiced]" checked>
To be Invoiced </label>
</div>
使用此脚本将2个复选框的值更改为true或false:
with this script that changes the value of 2 checkboxes in true or false:
<script type="text/javascript">
$('#tobeinvoiced').change(function(){
cb = $(this);
cb.val(cb.prop('checked'));
});
$('#invoiced').change(function(){
cb = $(this);
cb.val(cb.prop('checked'));
});
</script>
但是当我提交时,传递的值设置为null.
but when I submit, the values passed are set to null.
推荐答案
I've found the solution to my problem, this is the link : Solution.
我的代码变成:
<label class="col-md-6" for="invoiced">
<input type="checkbox" key="invoiced"/>
<input type="hidden" id="invoiced" value="0" name="project[invoiced]">
Invoiced </label>
<label class="col-md-6" for="tobeinvoiced">
<input type="checkbox" key="tobeinvoiced" checked/>
<input type="hidden" id="tobeinvoiced" value="1" name="project[tobeinvoiced]">
To be Invoiced </label>
使用此脚本:
$(document).ready(function () {
$('[key]').change(function () {
var key = $(this).attr('key');
$($('[name="project[' + key + ']"]')).val($(this).is(':checked') ? 'true' : 'false');
});
});
这篇关于在Laravel 5.1中无法发布复选框的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文