我正在使用Google Places API列出运输服务的接送地点。我们有两个字段,当输入时,自动提示结果。
当一个下拉列表#transport-type设置为第一个选项,value = 1时,输入字段#pick-up-location应该在其结果中添加'types'机场。
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程序员,所以它甚至可能是语法问题。我很感激你们能提供的任何见解。
谢谢你的时间!
答案 0 :(得分:0)
你错过了一个近距离并且有一个额外的; 请尝试以下
if ($('#transport-type').attr('value', '1')) {