【发布时间】:2013-09-16 11:45:22
【问题描述】:
这里我有一个代码function findPlaces,用于搜索框等中的位置对象。
function findPlaces(boxes,searchIndex) {
var request = {
bounds: boxes[searchIndex],
types: ["museum"]
};
这工作正常,但现在......
现在我想用列表/菜单中的值更改此类型,所以我这样做:
//JS CODE
function findPlaces(boxes,searchIndex) {
var request = {
bounds: boxes[searchIndex],
types: document.getElementById("select").selectedIndex
};
和 HTML 代码:
<label for="select"></label>
<select name="select" id="select">
<option>restaurant</option>
<option>bar</option>
<option>museum</option>
<option>gas_station</option>
</select>
并且此代码不会从列表/菜单中获取值并使用新值运行函数
我该如何解决?
【问题讨论】:
-
检查
types'值,它应该是一个int(所选选项的索引,如名称所述)。要获得所选选项的值,您必须这样做:document.getElementById("select")[document.getElementById("select").selectedIndex].value -
看这里:jsbin.com/UNuRexA/5,别再工作了
-
或者这个:jsbin.com/UNuRexA/6
标签: javascript jquery html list drop-down-menu