[英]disable/enable click event Jquery
我有一個ID為“ CB”的CheckBox和一個ID為“ BT”的按鈕。 我要驗證:
那么如果在Jquery內部,如何正確編寫腳本?
var CB = $("#CB");
var inital_CB = CB .is(":checked");
var BT= $("#BT").attr("disabled", !inital_CB);
CB .click(function() {
BT.attr("disabled", !this.checked);
});
如果您要做的只是根據是否選中該復選框來觸發一些代碼,請執行以下操作:
var theButton = document.getElementById("Button1");
var theCheckBox = document.getElementById("Checkbox1");
theButton.onclick = function () {
if (theCheckBox.checked) {
//Code that executes when checkbox is selected
}
else {
//Code that executes when checkbox is not selected
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.