在下拉菜单输入中设置Google地方信息的“类型" [英] Setting Google Places 'Types' on Dropdown Input
问题描述
我正在使用Google Places API列出运输服务的接送地点.我们有两个字段,在输入时会自动建议结果.
I'm using the Google Places API to list pick up and drop off locations for a transportation service. We have two fields that, when typed in, autosuggest results.
将下拉菜单#transport-type设置为第一个选项,值= 1时,则输入字段#pick-up-location应在其结果中添加类型"机场.
When a a dropdown, #transport-type, is set to the first option, value = 1, then the input field, #pick-up-location, should have 'types' airport added to its results.
JS:
function transport_types() {
if ($('#transport-type').val() == 1) {
var input = document.getElementById('pick-up-location');
var options = { types: ['airport'] };
autocomplete = new google.maps.places.Autocomplete(input, options);
}
if ($('#transport-type').val() == 2) {
var input = document.getElementById('drop-off-location');
var options = { types: ['airport'] };
autocomplete = new google.maps.places.Autocomplete(input, options);
}
google.maps.event.addDomListener(window, 'load', initialize);
}
下拉HTML:
<select id="transport-type" name="TransNeeded" required="true" tabindex="101" onChange="transport_types();">
<option value='0' selected='selected'>Where do you want to go?</option>
<option value='1' onfocus="enableGoogle('', true);" id="pick-up-type">Pick-Up Location is an Airport</option>
<option value='2' onfocus="enableGoogle('', true);" id="drop-off-type">Drop-Off Location is an Airport</option>
<option value='3' onfocus="enableGoogle('', true);" id="point-point-type">Point to Point or Charter</option>
</select>
输入HTML:
<input type="text" id="pick-up-location" name="PUFullAddress" tabindex="104" value="Pick-Up Location" required="true"
onblur="if(this.value.length==0) { $('#pick-up-location').attr('value', ''); }"
onkeypress="delay(50);"
onfocus="enableGoogle('PU', false);"
/>
<input id="drop-off-location" name="DOFullAddress" type="text" tabindex="105" value="Drop-Off Location" required="true"
onblur="if(this.value.length==0) { $('#drop-off-location').attr('value', ' '); }"
onkeypress="delay(50);"
onfocus="enableGoogle('DO', false);"
/>
我不是经验最丰富的jQuery程序员,因此它甚至可能是语法问题.感谢您提供的任何见解.
I'm not the most seasoned jQuery programmer, so it could even be an issue of syntax. I appreciate any insight you guys can provide.
感谢您的时间!
推荐答案
您缺少右括号,还有一个多余的内容;尝试以下
You're missing a close bracket and have an extra ; Try the following
if ($('#transport-type').attr('value', '1')) {
这篇关于在下拉菜单输入中设置Google地方信息的“类型"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!