[英]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.