如何检查是否选中了p:selectBooleanCheckbox?
下面的jquery脚本总是为p:selectBooleanCheckbox返回false或undefined,但它对h:selectBooleanCheckbox
的预期效果如下<h:form id="myform" enctype="multipart/form-data">
<p:selectBooleanCheckbox id="mycbx" value="#{mybean.cbxSelect}" />
</h:form>
<script type="text/javascript">
$('#myform\\:mycbx').click(function () {
console.log($(this).is(':checked')); //always return false!
console.log($(this).prop('checked')); //return undefined
});
</script>
答案 0 :(得分:0)
for primefaces组件使用widgetVar:
<h:form id="myform" enctype="multipart/form-data">
<p:selectBooleanCheckbox id="mycbx" widgetVar="cbx" value="#{mybean.cbxSelect}" />
</h:form>
<script type="text/javascript">
$('#myform\\:mycbx').click(function () {
console.log(cbx.isChecked()); //return true if check
});
widgetVar的简介:http://blog.hatemalimam.com/intro-to-primefaces-widgetvar/