问题
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