[英]check the checkbox is check or uncheck
I want to know if the user has checked the checkbox and if so, then it should disable the date;我想知道用户是否选中了复选框,如果是,那么它应该禁用日期; if unchecked, then enable the date.
如果未选中,则启用日期。 Change event is there on checkbox
复选框上有更改事件
$('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');
}
});
This is short and simple.这是简短而简单的。
$('input[type=checkbox]').on('click', function() {
$('#MainContent_txtSrchToDate').prop('disabled', $(this).is(":checked"));
});
To check is a checkbox is checked or not, you can simply do it like this:要检查一个复选框是否被选中,你可以简单地这样做:
$('#chkShowAll').checked
It returns true if checked else it returns false如果选中则返回 true,否则返回 false
Try this one:试试这个:
$('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");
}
This show checkbox is checked or not此显示复选框是否选中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.