作者热门文章
- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我正在使用 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/
我是一名优秀的程序员,十分优秀!