我正在使用PrimeFaces 6.1 widgetVar
来启用和禁用网页上的多个元素。 我正在使用以下代码:
JavScript/jQuery:
PF('widget_select_one_button_1').getJQ().parent().removeAttr('disabled');
PF('widget_select_one_button_1')..getJQ().parent().attr("disabled", true);
.XHTML:
<h:form id="form-1">
<p:selectOneButton id="button-1" value="#{search.drawings}">
<f:selectItems value="#{search.drawings}" var="x" itemLabel="#{drawings}" itemValue="#{drawings}"/>
</p:selectOneButton>
</h:form>
我已经验证我使用的是正确的widgetVar
,因为我能够启用和禁用selectOneRadio
。 当我决定将selectOneRadio
更改为selectOneButton
时,我找不到有关如何启用或禁用该元素的任何信息。
我使用了上面显示的JavaScript的多种变体。我尝试在widgetVar
变量上调用.enable()
/.disable()
,然后使用我尝试添加和删除disabled
属性的jQuery对象。我也尝试了相同的方法(如上所示)jQuery对象的父对象。
有没有人知道如何启用或禁用selectOneButton
?
我使用 css 选择器通过这些元素的后代搜索所有无线电输入,然后在每个项目上应用禁用功能:
PF('yourWidgetVarName').getJQ().find('input[type="radio"]').each(function (index, element) { $(this).attr("disabled", true); });
请参阅:https://api.jquery.com/find/