admin管理员组文章数量:1425665
I'm using the AdminLTE theme (which implements bootstrap) and I have a checkbox on my page. 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)
I now wish to change the checked property of the checkbox with jQuery. How would I go about doing this? 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.
I'm using the AdminLTE theme (which implements bootstrap) and I have a checkbox on my page. 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)
I now wish to change the checked property of the checkbox with jQuery. How would I go about doing this? 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.
Share Improve this question edited Aug 20, 2014 at 3:50 Paul McLean asked Aug 20, 2014 at 2:49 Paul McLeanPaul McLean 3,5706 gold badges27 silver badges36 bronze badges5 Answers
Reset to default 4try below code
$("#subscribeAddress").iCheck('uncheck');
how about plain old-fashioned javascript?
document.getElementById("subscribeAddress").checked = true;
$("#subscribeAddress").prop("checked", true);
works fine.
here's a fiddle for it.
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.
Is directly modifying this div considered to be the correct way to do this? 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
本文标签:
版权声明:本文标题:javascript - Change 'checked' property of checkbox using jQuery and bootstrap (AdminLTE theme) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745455516a2659083.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论