[英]Disabling checkbox after it has been checked
我正在使用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;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.