我有一个 PrimeFaces p:selectBooleanCheckbox
:
<p:selectBooleanCheckbox styleClass="myCLass" onchange="callsMethod();" value="true" />
我想要这样的东西:
$('.myCLass').prop( 'checked', true )
用于动态设置 p:selectBooleanCheckbox
的值。
最佳答案
这比使用 widgetVar 简单多了。
- 将 widgetVar 添加到您的组件中,例如...
<p:selectBooleanCheckbox widgetVar="wgtMyCheckBox" onchange="callsMethod();" />
- 在您的 Javascript 代码中使用 WidgetVar 来获取或设置值。
PF('wgtMyCheckBox').isChecked(); -- returns current state
PF('wgtMyCheckBox').check(); -- checks the box
PF('wgtMyCheckBox').uncheck(); -- unchecks the box
PF('wgtMyCheckBox').toggle(); -- toggles the current state to the opposite state
如果你想选中屏幕上的所有复选框,你可以遍历小部件。
for (var widgetVar in PrimeFaces.widgets) {
var widget = PrimeFaces.widgets[widgetVar];
if (widget && widget instanceof PrimeFaces.widget.SelectBooleanCheckbox) {
widget.check();
}
}
关于javascript - 如何修改一组p :selectBooleanCheckboxes with the same class using jQuery?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54869043/