[英]check the checkbox is check or uncheck
我想知道用户是否选中了复选框,如果是,那么它应该禁用日期; 如果未选中,则启用日期。 复选框上有更改事件
$('input[type=checkbox]:checked').click(function () {
if ($('#chkShowAll').prop('checked')) {
$("#MainContent_txtSrchFromDate").attr('readonly', 'readonly');
$("#MainContent_txtSrchToDate").attr('readonly', 'readonly');
}
else {
$("#MainContent_txtSrchFromDate").removeAttr('readonly', 'readonly');
$("#MainContent_txtSrchToDate").removeAttr('readonly', 'readonly');
}
});
这是简短而简单的。
$('input[type=checkbox]').on('click', function() {
$('#MainContent_txtSrchToDate').prop('disabled', $(this).is(":checked"));
});
要检查一个复选框是否被选中,你可以简单地这样做:
$('#chkShowAll').checked
如果选中则返回 true,否则返回 false
试试这个:
$('input[type=checkbox]').click(function() { let dateElements = $("#MainContent_txtSrchFromDate, #MainContent_txtSrchToDate"); if ($(this).is(":checked")) { dateElements.prop("readonly", true); } else { dateElements.prop("readonly", false); } });
if($("#checkbox_id").is(':checked')){
console.log("checked");
}
else{
console.log("not checked");
}
此显示复选框是否选中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.