jQuery UI-自动完成源取决于不同输入中的选定选项 [英] jQuery UI - Autocomplete source dependent from selected option in different input
本文介绍了jQuery UI-自动完成源取决于不同输入中的选定选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用jquery-ui.min.js中的自动完成脚本.所以在代码中我有:
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" >
和脚本:
<script>
$(function() {
var US= ["City1", "City2", "City3"];
var UK= ["UK_City1", "UK_City2", "UK_City3"];
$("#city").autocomplete({
source: US
});
});
</script>
问题是如何根据选择ID ="Country"中用户选择的文本更改源?这也是此脚本: http://jsbin.com/adopo3/35/edit >
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
推荐答案
最简单的方法是使用选项方法更改源.我已经在此处修改了您的示例代码.
Simplest way is to use option method to change the source. I have modified your example code to illustrate it here.
另一种方法是向source选项提供回调函数.请参见此处
Another way would be to supply callback function to the source option. See that here
这篇关于jQuery UI-自动完成源取决于不同输入中的选定选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文