gpt4 book ai didi

jquery - iCheck 和 jQuery 序列化

转载 作者:行者123 更新时间:2023-12-01 04:40:33 26 4
gpt4 key购买 nike

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

我猜测,当用户点击要选中的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>

当您检查它时,它会将您指定的检查类(在本例中为“checked”)添加到 div。

我要做的只是隐藏输入,当您单击 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 将获取这些输入:)

关于jquery - iCheck 和 jQuery 序列化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38805372/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com