如何在JavaScript中使用JSF2.0值?
我有一个JSF下拉框如何在JavaScript中使用JSF2.0值?,javascript,jsf,jsf-2,Javascript,Jsf,Jsf 2,我有一个JSF下拉框 <f:selectItem itemValue="0" itemLabel="Select a criterion" noSelectionOption="true"></f:selectItem> <f:selectItem itemValue="4" itemLabel="Map location: Main land US"></f:selectItem> <f:selectItem itemValue="5" i
<f:selectItem itemValue="0" itemLabel="Select a criterion" noSelectionOption="true"></f:selectItem>
<f:selectItem itemValue="4" itemLabel="Map location: Main land US"></f:selectItem>
<f:selectItem itemValue="5" itemLabel="Map location: Alaska"></f:selectItem>
<f:selectItem itemValue="6" itemLabel="Map location: Hawaii"></f:selectItem>
我想添加一些if语句,让我将latlong部分设置为不同的项
if (itemValue == 5)
{
//alaska
var myLatlng = new google.maps.LatLng(64.0000,-150.0000)
}
if (itemValue == 5)
{
//hawaii
var myLatlng = new google.maps.LatLng(21.3114,-157.7964)
//end new shit
}
但是我不确定如何将项目值从JSF下拉列表传递到javascript函数
最好的方法是什么?
谢谢。如果您在下拉列表中查看呈现的HTML,这会有所帮助,因为Javascript只能处理这些内容。基本上,您必须按id、类或任何其他选择器选择HTML元素,然后获取其值 如果您使用的是jQuery,以下是获取itemValue的简单方法:
var selectedItemValue = $('.mySelector').children("option:selected").val();
…其中mySelector是分配给selectOneMenu标记的样式类。您可以在此处找到许多替代方法:
var selectedItemValue = $('.mySelector').children("option:selected").val();