Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iCheck和jQuery序列化_Jquery_Icheck - Fatal编程技术网

iCheck和jQuery序列化

iCheck和jQuery序列化,jquery,icheck,Jquery,Icheck,我使用iCheck插件来美化我的复选框。但是,当我使用jQuery serialize从表单中收集所有填写的数据时,选中的复选框不会被看到,也不会通过post提交 我猜当用户单击要选中的iCheck复选框时,输入类型复选框的状态实际上并没有设置为选中状态 如何做到这一点?使用普通HTML复选框可以通过序列化很好地选中 表格的相关部分: <div class="form-group"> <label class=""> <input type="checkbox" c

我使用iCheck插件来美化我的复选框。但是,当我使用jQuery serialize从表单中收集所有填写的数据时,选中的复选框不会被看到,也不会通过post提交

我猜当用户单击要选中的iCheck复选框时,输入类型复选框的状态实际上并没有设置为选中状态

如何做到这一点?使用普通HTML复选框可以通过序列化很好地选中

表格的相关部分:

<div class="form-group">
<label class="">
<input type="checkbox" class="minimal" id="remote" name="remote" value="1">
</label>                        
</div>
提交功能:

$.ajax({
  type: "POST",
  url: '/taken/action.php',
  data: $form.serialize(),
  dataType: "json",
  ............

在我看来,iCheck将复选框包装在一个div中,如下所示:

<div class="icheckbox_minimal" aria-checked="true" aria-disabled="false">
    <input tabindex="5" type="checkbox" id="minimal-checkbox-1" style="position: absolute; top: -20%; left: -20%; display: block; width: 140%; height: 140%; margin: 0px; padding: 0px; border: 0px; opacity: 0; background: rgb(255, 255, 255);">
    <ins class="iCheck-helper" style="position: absolute; top: -20%; left: -20%; display: block; width: 140%; height: 140%; margin: 0px; padding: 0px; border: 0px; opacity: 0; background: rgb(255, 255, 255);"></ins>
</div>

现在jQuery将获取这些输入:)

谢谢,这让我走上了正确的道路。创建一个隐藏字段,并使用iCheck的回调函数对其进行更改$(“#onsitecheckbox”).on('ifChecked',函数(事件){alert(event.type+'callback');$(“#location”).val('site');});$('#onsitecheckbox').on('ifUnchecked',函数(事件){alert(event.type+'callback');$(“#location”).val('remote');})@Mbrouwer88很高兴知道:)
<div class="icheckbox_minimal" aria-checked="true" aria-disabled="false">
    <input tabindex="5" type="checkbox" id="minimal-checkbox-1" style="position: absolute; top: -20%; left: -20%; display: block; width: 140%; height: 140%; margin: 0px; padding: 0px; border: 0px; opacity: 0; background: rgb(255, 255, 255);">
    <ins class="iCheck-helper" style="position: absolute; top: -20%; left: -20%; display: block; width: 140%; height: 140%; margin: 0px; padding: 0px; border: 0px; opacity: 0; background: rgb(255, 255, 255);"></ins>
</div>
$(".icheckbox_minimal").click(function(){
    // You might want more logic in here since You probably have more then
    // One check box to toggle.
    var val = $("#myHiddenIpnut").val();
    $("#myHiddenIpnut").val(val === "true" ? "false" : "true");
});