我正在使用 JSF 和 Javascript
复选框
<h:selectBooleanCheckbox onclick="handlePaymentButtons()"
class="chkBox"></h:selectBooleanCheckbox>Yes I agree terms and Conditions
JS
<script>
function handlePaymentButtons(){
console.log("we are here..");
var box = document.getElementsByClassName("chkBox");
box.disabled =true;
console.log(box);
gButton.enable();
}
</script>
我只是想禁用当前选中的复选框。
但我仍然可以选中/取消选中该复选框。
最佳答案
这是一个HTMLCollection
,一个集合,返回值getElementsByClassName
。您要么需要迭代它,要么通过索引从集合中获取特定元素。由于集合的.length
为1
,因此您可以简单地编写box[0].disabled = true
。
或者,您也可以使用querySelector
,它仅返回一个元素(如果有):
var box = document.querySelector(".chkBox");
box.disabled = true;
关于javascript - 选中后禁用复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52530392/