如何获得<;p:选择一个功能表>;使用JQuery的值
如何使用Jquery或javascript获取select组件值 下面是MyJSF代码如何获得<;p:选择一个功能表>;使用JQuery的值,jquery,jsf,primefaces,Jquery,Jsf,Primefaces,如何使用Jquery或javascript获取select组件值 下面是MyJSF代码 <h:form> <p:selectOneMenu style="width:150px" id="id" onchange="onCall()"> <f:selectItem itemLabel="Select" itemValue=""></f:selectItem> <f:selec
<h:form>
<p:selectOneMenu style="width:150px" id="id" onchange="onCall()">
<f:selectItem itemLabel="Select" itemValue=""></f:selectItem>
<f:selectItem itemLabel="Other" itemValue="Other"></f:selectItem>
</p:selectOneMenu>
<p:selectBooleanCheckbox id="flag"/>
<p:inputText id="name" value="#{mybean.value}/>
</h:form>
您可以在此函数中传递this
:
onchange="onCall(this)"
我假设您已经在全局范围内定义了这个onCall
函数,那么您可以这样做:
onCall(el){
alert(el.value);
}
由于Primefaces为其组件提供了Javascript API,因此您可以通过widgetVar
xhtml
我已经尝试了一些代码,但没有人能工作。如果你能以这种方式发布呈现的html,而不是jsf代码,如果你能像你提到的那样发布你的javascript,你已经应用了一些内联js事件,那就更好了。为什么你要用alert
而不是console.log()进行调试
?这只是OP需要寻找答案的一个例子。我知道console.log()
更适合使用,但这只是我的假设,我想告诉OP尝试这样做以获取函数中的值。哦,工作正常,但我想设置checkbox=true值。当然,是否有任何选项可以设置为true并隐藏,但这个问题与上述问题无关,你可以问另一个问题解释你的情况,在这种情况下,我们避免混淆。。。
<p:selectOneMenu widgetVar="selectWV">
</p:selectOneMenu>
PF('selectWV').getSelectedValue();//gets the value
PF('selectWV').getSelectedLabel();//gets the label