我正在使用jQuery Autocomplete,我有一些代码。我试着通过select修改" source“自动补全,但是当我改变source自动补全不起作用。我尝试使用.change,.on,.click进行重新初始化,但仍然不起作用。当我使用未修改的源代码时,自动补全工作正常。
$('#myselect').change(function() {
$('#part_q').prop("disabled", false).focus();
var brand = $('#myselect').val();
$('#part_q').autocomplete({
source: 'https://example.com/search/?' + brand
});
});<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<select id="myselect">
<option value="" selected="selected" disabled="">Select Brand</option>
<option value="1">Some brand</option>
<option value="2">Some brand 2</option>
<option value="3">Some brand 3</option>
</select>
<input disabled="" placeholder="Model Name" type="text" id="part_q" name="part_q">
发布于 2017-12-18 02:55:59
这是一个简单的代码片段,展示了如何实现自动完成刷新功能,请使用此代码,并让我知道如果在您的用例中实现它有任何问题!
var arr = [[1,1],[2,2],[3,3][4,4]];
$('#myselect').change(function() {
$('#part_q').prop("disabled", false).focus();
var brand = $('#myselect').val();
$('#part_q').autocomplete("option", { source: arr[brand] });
});
$("#part_q").autocomplete({
source: []
});<link href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<select id="myselect">
<option value="" selected="selected" disabled="">Select Brand</option>
<option value="0">Some brand</option>
<option value="1">Some brand 2</option>
<option value="2">Some brand 3</option>
<option value="4">Some brand 4</option>
</select>
<input disabled="" placeholder="Model Name" type="text" id="part_q" name="part_q">
https://stackoverflow.com/questions/47858180
复制相似问题