简体   繁体   English

如何知道是否使用JavaScript选择了primefaces selectBooleanCheckbox?

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

I want to get p:selectBooleanCheckbox component and check if it is selected or not using javascript 我想获取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>

I want on calculateTotalRatio() function check if the checkbox is checked or not and depending on it update ratio1 input text with value 我想在calculateTotalRatio()函数上检查该复选框是否已选中,并根据它更新ratio1输入带有值的文本

You can define the widgetVar of your selectBooleanCheckbox 您可以定义selectBooleanCheckbox的widgetVar

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

You can access in js the Primefaces object in these ways 您可以通过以下方式在js中访问Primefaces对象

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

So, to get the checkbox state you can use 因此,要获取复选框状态,您可以使用

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM