[英]Disable button if checkbox is checked and label is a specific text
我有一個帶有數據網格的表(每行中的復選框和標簽)。 我想通過檢查 label 是否為“禁止”來禁用按鈕。 用戶可以選中多個復選框。 所以我的問題是如何獲取所有選中的復選框,然后檢查每個選定行中的 label 是否具有值“Forbidden”,以便我可以禁用該按鈕。
我試過這樣的事情:
$(function() {
checkboxes = document.querySelectorAll('[id=checkId]');
var validateBtn = $('button[name="btnVal"]');
checkboxes.forEach((cb) => {
cb.addEventListener('change', checkStatus);
});
function checkStatus() {
//to-do
// if ($(this).is(":checked")) {
var label = document.getElementById('statusLabel');
if (label.textContent == "Forbidden") {
validateBtn.prop('disabled', true);
}
}
});
表格如下所示: enter image description here在這種情況下,按鈕應該被禁用,因為我們選擇了禁止狀態。
您可以檢查復選框的屬性並根據以下內容禁用按鈕:
$('#id_of_your_checkbox').click(function() {
if ($(this).is(':checked')) {
$('#id_of_your_button').attr('disabled', 'disabled');
} else {
$('#id_of_your_button').removeAttr('disabled');
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.