$('#btnSelectAll').click(function() {
$('.inputchbox').attr('checked', true);
$('fieldset').find('img').hide(); // datepicker hide
});
//Cancel will deselect all checkboxes and hide submit and Cancel Buttons
$('#btnCancel').click(function() {
$('.inputchbox').attr('checked', false);
$('fieldset').find('img').show(); //datepicker show
});
这是我的selectAll和cancelall点击事件..工作正常..
除此之外,单击复选框上的个别选择
$(".inputchbox").change(function() {
if ($('.inputchbox').is(':checked')) {
$(this).closest("fieldset").find('img').hide(); // Datepicker hide
}
else {
$(this).closest("fieldset").find('img').show(); // datepicker show
}
});
</script>
在selctAll和cancelall上我可以在我的字段集中显示和隐藏我的所有日期选择器图像
关于复选框的个别选择也很有效。
我的问题是..
当我选择所有我可以隐藏我的所有日期选择图像后,... 如果单独在我的每个复选框上单独显示我的图像它不工作,甚至没有进入复选框选择的其他条件? 是有什么不对的 感谢
答案 0 :(得分:2)
$(".inputchbox").change(function() {
if ($('.inputchbox').is(':checked')) {
// use this here ^---< $(this).is(':checked')
答案 1 :(得分:2)
马上,我想你想改变if语句来使用$(this)而不是类选择器.inputchbox,这至少应该让你的其他人触发
$(".inputchbox").change(function() {
if ($(this).is(':checked')) {
$(this).closest("fieldset").find('img').hide(); // Datepicker hide
}
else {
$(this).closest("fieldset").find('img').show(); // datepicker show
}
});
答案 2 :(得分:1)
作为已接受答案的替代方案,在if
语句中很少有理由.is(':checked')
,您可以直接使用DOM .checked
属性,.toggle(bool)
而不是显示/隐藏,像这样:
$(".inputchbox").change(function() {
$(this).closest("fieldset").find('img').toggle(!this.checked);
});