iCheck 和 jQuery 序列化
iCheck and jQuery serialize
我使用 iCheck 插件来美化我的复选框。但是,当我使用 jQuery 序列化从表单中收集所有填写的数据时,post 看不到或未提交选中的复选框。
我猜想当用户点击iCheck框被选中时,输入类型复选框的状态实际上并没有设置为选中状态。
如何做到这一点?使用正常的 HTML 复选框可以通过序列化很好地拾取。
表格相关部分:
<div class="form-group">
<label class="">
<input type="checkbox" class="minimal" id="remote" name="remote" value="1">
</label>
</div>
脚本:
//iCheck for checkbox and radio inputs
$('input[type="checkbox"].minimal, input[type="radio"].minimal').iCheck({
checkboxClass: 'icheckbox_minimal-blue',
radioClass: 'iradio_minimal-blue',
checkedClass: 'checked',
});
提交功能:
$.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>
当您检查它时,它会将您指定的已检查 class 添加到 div。
,在本例中为 'checked'
我要做的只是隐藏输入,当您单击 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");
});
现在 jQuery 将获取这些输入:)
我使用 iCheck 插件来美化我的复选框。但是,当我使用 jQuery 序列化从表单中收集所有填写的数据时,post 看不到或未提交选中的复选框。
我猜想当用户点击iCheck框被选中时,输入类型复选框的状态实际上并没有设置为选中状态。
如何做到这一点?使用正常的 HTML 复选框可以通过序列化很好地拾取。
表格相关部分:
<div class="form-group">
<label class="">
<input type="checkbox" class="minimal" id="remote" name="remote" value="1">
</label>
</div>
脚本:
//iCheck for checkbox and radio inputs
$('input[type="checkbox"].minimal, input[type="radio"].minimal').iCheck({
checkboxClass: 'icheckbox_minimal-blue',
radioClass: 'iradio_minimal-blue',
checkedClass: 'checked',
});
提交功能:
$.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>
当您检查它时,它会将您指定的已检查 class 添加到 div。
,在本例中为 'checked'我要做的只是隐藏输入,当您单击 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");
});
现在 jQuery 将获取这些输入:)