[英]Disabling checkbox after it has been checked
I am using JSF and Javascript 我正在使用JSF和Javascript
Checkbox 复选框
<h:selectBooleanCheckbox onclick="handlePaymentButtons()"
class="chkBox"></h:selectBooleanCheckbox>Yes I agree terms and Conditions
JS JS
<script>
function handlePaymentButtons(){
console.log("we are here..");
var box = document.getElementsByClassName("chkBox");
box.disabled =true;
console.log(box);
gButton.enable();
}
</script>
I simply want to disable the currently checked checkbox. 我只是想禁用当前选中的复选框。
but i can still check/uncheck the checkbox. 但我仍然可以选中/取消选中该复选框。
That's a HTMLCollection
, a collection, returned value of getElementsByClassName
. 那是一个HTMLCollection
,一个集合,返回值getElementsByClassName
。 You either need to iterate through it or get a specific element by index from the collection. 您要么需要遍历它,要么需要从集合中按索引获取特定的元素。 Since the .length
of the collection is 1
, you can simply code box[0].disabled = true
. 由于集合的.length
为1
,因此您可以简单地将box[0].disabled = true
编码。
Alternatively, you can also use querySelector
which returns only one element (if any): 另外,您也可以使用querySelector
,它仅返回一个元素(如果有):
var box = document.querySelector(".chkBox");
box.disabled = true;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.