1

我正在使用 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 程序员,所以它甚至可能是语法问题。我很感激你们能提供的任何见解。

谢谢你的时间!

4

1 回答 1

0

您缺少一个右括号并有一个额外的 ; 尝试以下

 if ($('#transport-type').attr('value', '1')) {
于 2012-10-02T13:13:16.910 回答