Primefaces 5.0 selectCheckboxMenu 组件问题,无法在 jQuery 中获取复选框的 id 来获取选中的复选框的数量。
我想使用 selectCheckboxMenu
组件中选中的复选框数量更新标签文本。两种方法我都试过了
- Ajax
- jQuery 获取复选框 ID。
下面是我在 .xhtml 文件中的代码。 ajax 调用后,我发现了这样的错误。在 primefaces.js 第 22 行中未定义 closeer。
<p:selectCheckboxMenu id="pioDocType"
value="#{pioReportActionBean.selectedOutPutData}"
label="#{pioReportActionBean.lbl_docType}" filter="true"
filterMatchMode="startsWith" panelStyle="width:250px" styleClass="rep_checkbox" widgetVar="myCheckbox" >
<f:selectItems value="#{pioReportActionBean.inPutData}"
var="outPutData" itemLabel="#{outPutData.displayName}"
itemValue="#{outPutData.displayId}" />
<p:ajax event="change" listener="#{pioReportActionBean.populateLabelDocType}"
update="pioDocType" />
</p:selectCheckboxMenu>
jQuery 代码..
var count = $("#pioDocType input:checked").length;
alert(count);
count = $("#myCheckbox:checked").length;
alert(count);
count = $("input.rep_checkbox .ui-selectcheckboxmenu-panel .ui-selectcheckboxmenu-header .ui-chkbox-box:checked").length;
alert(count);
我正在使用 spring 3 、 Primefaces 5.0 、 JDk 7 。
最佳答案
你可以试试这个
var count = PF('myCheckbox').inputs.filter(":checked").length;
//change label
PF('myCheckbox').jq.find('.ui-selectcheckboxmenu-label').text(count + ' selected');
关于jquery - selectCheckboxMenu 无法获取选中复选框的数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25762661/