jQuery UI - Autocomplete source dependent from selected option in different input

孤者浪人 提交于 2019-12-11 04:47:24

问题


I would like to use Autocomplete script from jquery-ui.min.js. So in code I have:

<select id="country"><option value="">Choice one</option>
<option value="1">US</option>
<option value="2">UK</option></select>
<input type="text" id="city" >

And the script:

<script>
$(function() {
  var US= ["City1", "City2", "City3"];
  var UK= ["UK_City1", "UK_City2", "UK_City3"];
  $("#city").autocomplete({  
  source: US  
  });
}); 
</script>

The question is how to change source dependent on user selected text from Select ID="Country"? Here is also this script: http://jsbin.com/adopo3/35/edit


回答1:


Simplest way is to use option method to change the source. I have modified your example code to illustrate it here.

Another way would be to supply callback function to the source option. See that here



来源:https://stackoverflow.com/questions/7992712/jquery-ui-autocomplete-source-dependent-from-selected-option-in-different-inpu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!