gpt4 book ai didi

javascript - iCheck 和手动设置复选框以选中

转载 作者:数据小太阳 更新时间:2023-10-29 04:26:49 25 4
gpt4 key购买 nike

我正在使用 iCheck framework我有两个输入

<input name="group" id="id1" type="radio" checked>
<input name="group" id="id2" type="radio">
<input name="group" id="id3" type="radio">
<input name="group" id="id4" type="radio">

单击时调用 ajax 函数。如果出现问题,我想将选中的属性设置回之前选择的输入。

var currentChecked = $("input[name='group']:radio:checked");

$("input[name='group']:radio").each(function() {
$(this).on('ifChecked', function(){
$.ajax({
url: "/ajax/something/"
})
.done(function (data) {
currentChecked = $(this);
})
.fail(function (data) {
$(this).removeAttr('checked');
currentChecked.prop('checked', true);
});
});
});

但这不会重置选中的复选框。 iCheck 框架中有什么是我看不到的?有什么解决办法吗?

最佳答案

实际上在 iCheck 的情况下,您需要更新 iCheck 以反射(reflect) Jquery 上的更改。

您可以使用 iCheck('update') 进行更新

$(this).iCheck('update');

使用 jquery 选中或取消选中单选按钮后。

另一个解决方案只是使用他的预定义函数检查取消选中 iCheck

<input name="group" id="id1" type="radio" checked>

如果上面的是你的单选按钮,你可以使用 jquery 部分中的代码,如下所示

$('#id1').iCheck('uncheck'); //To uncheck the radio button
$('#id1').iCheck('check'); //To check the radio button

在这种情况下不需要使用iCheck('update')

关于javascript - iCheck 和手动设置复选框以选中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36942541/

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