[英]Change 'checked' property of checkbox using jQuery and bootstrap (AdminLTE theme)
I'm using the AdminLTE theme (which implements bootstrap) and I have a checkbox on my page.我正在使用AdminLTE主题(实现引导程序)并且我的页面上有一个复选框。 It gets rendered as follows -
它呈现如下 -
<div class="icheckbox_minimal" style="position: relative;" aria-checked="false" aria-disabled="false">
<input id="subscribeAddress" type="checkbox" style="position: absolute; opacity: 0;">
<ins class="iCheck-helper" style="position: absolute; top: 0%; left: 0%; display: block; width: 100%; height: 100%; margin: 0px; padding: 0px; background: none repeat scroll 0% 0% rgb(255, 255, 255); border: 0px none; opacity: 0;"></ins>
</div>
(note how a sprite is used to display the checkbox, while the actual input element is given an opacity of 0) (请注意如何使用 sprite 来显示复选框,而实际输入元素的不透明度为 0)
I now wish to change the checked property of the checkbox with jQuery. How would I go about doing this?我现在想用 jQuery 更改复选框的选中属性。我 go 如何执行此操作? I have tried the following without any luck -
我尝试了以下但没有任何运气 -
$("#subscribeAddress").prop("checked", true);
$(".icheckbox_minimal").prop("aria-checked", true);
Update: I have found a solution to my question and posted an answer below, but am still open to suggestions on better approaches.更新:我已经找到了我的问题的解决方案并在下面发布了答案,但我仍然愿意接受有关更好方法的建议。
尝试下面的代码
$("#subscribeAddress").iCheck('uncheck');
普通的老式javascript怎么样?
document.getElementById("subscribeAddress").checked = true;
Try this尝试这个
$('#checkAll').on('ifChanged', function(event){
if(this.checked){
$('input').iCheck('check')
}
else{
$('input').iCheck('uncheck')
}
})
I hope this will help you.我希望这能帮到您。
It seems that adding the "checked" class to div of class "icheckbox_minimal" is what I was looking for. 看来,向我的“ icheckbox_minimal”类的div添加“ checked”类是我想要的。
Is directly modifying this div considered to be the correct way to do this? 是否直接修改此div被认为是执行此操作的正确方法? Or should I be another way?
还是我应该换个方式?
I'll leave my question unanswered for a little while, to give someone a chance to supply a better answer (if one exists). 我将让我的问题待一会儿,以便给某人提供更好答案的机会(如果存在的话)。 I feel like marking my own answer is cheating :p
我觉得标记自己的答案是在欺骗:p
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.