如何知道素数面selectBoolean复选框是否使用javascript选中

How to know that primefaces selectBooleanCheckbox is selected or not using javascript?

本文关键字:是否 javascript 选中 复选框 selectBoolean 何知道      更新时间:2023-09-26

我想获取p:selectBooleanCheckbox组件,并使用javascript 检查它是否被选中

<h:dataTable value="#{controller.list}" var="item">
    <h:column>
        <f:facet name="header">Ratio1</f:facet>
        <h:panelGrid columns="2">
            <p:inputText id="ratio1" readonly="#{true}" disabled="true" styleClass="ratio1"/>
            <h:outputText value="%" />
        </h:panelGrid>
        <p:selectBooleanCheckbox id="report1"  onchange="calculateTotalRatio()" value="#{controller.value}" valueChangeListener="#{fISHController.onCaseTestItemPatternReportFlagChange()}">    
        </p:selectBooleanCheckbox>          
    </h:column>

我想在calculateTotalRatio()功能上检查复选框是否被选中,并根据它更新比率1输入文本的值

您可以定义selectBoolean复选框的widgetVar

<p:selectBooleanCheckbox id="check" widgetVar="myCheckbox" value="#{myBacking.value}"/>

您可以通过以下方式在js中访问Primefaces对象

directly with myCheckbox
PF("myCheckbox")
window["myCheckbox"]
PrimeFaces.widgets["myCheckbox"]

因此,要获得复选框状态,可以使用

myCheckbox.input.is(':checked')
PF("myCheckbox").input.is(':checked')
window["myCheckbox"].input.is(':checked')
PrimeFaces.widgets["myCheckbox"].input.is(':checked')