[英]How to disable specific checkboxes when one checkbox is clicked? JavaScript
[英]How to disable Checkbox unless one checkbox is clicked
我有兩個復選框,當單擊一個復選框時,必須啟用另一個復選框,否則應將其禁用(復選框和文本)
HAML代碼:
%label.checkbox
= check_box_tag 'Name'
Name
%label.checkbox
= check_box_tag 'Description'
Description
您可以只使用一些jQuery:
HTML:
<input type="checkbox" class="enabler" />
<input type="checkbox" class="optional" disabled />
<input type="checkbox" class="optional" disabled />
JS:
$(".enabler").on("change", function(e) {
$(".optional").prop("disabled", !$(this).prop("checked"));
});
嗯,聽起來您想使單選按鈕可以提供的功能過於復雜
的HTML
<input type="checkbox" onclick="func();" />
<input type="checkbox" id="dis" disabled="disable" />
jQuery查詢
function func(){
var optObj = $("checkbox#dis");
if(optObj.attr("disabled"))
optObj.removeAttr("disabled");
else
optObj.attr("disabled", "disable");
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.