选中/取消选中-如果Checked不起作用 [英] Check/Uncheck - ifChecked not working
本文介绍了选中/取消选中-如果Checked不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
更新:我正在使用以下插件
UPDATE: I'm using the following plugin
我正在尝试检查用户刷新页面或重新加载页面时是否选中了该复选框,这是我使用过的,但是我已经进行了调试,并且从不执行second IF
条件
I'm trying to check if the checkbox is checked when the user refresh the page or reload the page and here is what I have used but I have done the debugging and it never execute the second IF
condition
$('input').on('ifChecked', function (event) {
if ($("input#CreatePart").is(':checked')) {
alert('checked');
}
});
$('input').on('ifUnchecked', function (event) {
if ($("input#CreatePart").is(':checked')) {
alert('un-checked');
}
});
<input checked="checked" class="icheck" data-val="true"
data-val-required="The Create new Part field is required."
id="CreatePart" name="CreatePart" type="checkbox" value="true"
/>
<input name="CreatePart" type="hidden" value="false" />
推荐答案
尝试:
页面加载:
alert($('input').is(':checked'));
http://jsfiddle.net/9ypwjvt4/18/
其他用途:
$(document).ready(function () {
$('input').iCheck({
checkboxClass: 'icheckbox_square-orange',
radioClass: 'iradio_square-orange',
increaseArea: '20%' // optional
});
$('input').on('ifChecked', function(event){
alert('Checked');
});
$('input').on('ifUnchecked', function(event){
alert('unchecked');
});
});
jsfiddle: http://jsfiddle.net/9ypwjvt4/17/
jsfiddle: http://jsfiddle.net/9ypwjvt4/17/
这篇关于选中/取消选中-如果Checked不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文