Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.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
Javascript 如何从jsf selectonelistbox itemLabel文本中读取文本(值)?_Javascript_Jsf_Jsf 2_Selectonelistbox - Fatal编程技术网

Javascript 如何从jsf selectonelistbox itemLabel文本中读取文本(值)?

Javascript 如何从jsf selectonelistbox itemLabel文本中读取文本(值)?,javascript,jsf,jsf-2,selectonelistbox,Javascript,Jsf,Jsf 2,Selectonelistbox,下面是我的JSF <h:selectOneMenu id="lstmonth" required="true" value="#{secdeal.month}"> <f:selectItem itemValue="JAN" itemLabel="01-January"/> <f:selectItem itemValue="FEB" itemLabel="02-February"/> <f:selectItem it

下面是我的JSF

<h:selectOneMenu id="lstmonth"
required="true"
value="#{secdeal.month}">
<f:selectItem
    itemValue="JAN"
    itemLabel="01-January"/>
<f:selectItem
    itemValue="FEB"
    itemLabel="02-February"/>
<f:selectItem
    itemValue="MAR"
    itemLabel="03-March"/>

在javascript中(在同一文件中)

我想阅读selecteditem的itemLabel文本。(即:如果我选择1月1日,我希望在我的var x中输入相同的文本)

x=getElementById('Form:lstmount')。itemLabel//不工作 x=getElementById('Form:lstmount')。innerText//不工作--返回所有月份

如何获取itemLabel文本?请建议

实际上,我想要1月1日的x=01(选定项目)

给你:

var ele = document.getElementById("Form:lstmonth");
var selectedIndex = ele.selectedIndex;
var x = ele.options[selectedIndex].text;

有什么理由不接受这个解决方案吗?对你不起作用吗?对不起,起作用了。如果我错了,我会被拒绝的!