Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何获得<;p:选择一个功能表>;使用JQuery的值_Jquery_Jsf_Primefaces - Fatal编程技术网

如何获得<;p:选择一个功能表>;使用JQuery的值

如何获得<;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

如何使用Jquery或javascript获取select组件值

下面是MyJSF代码

<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