我的表单上有2个自动填充文本框。我想要做的是动态更改第二个自动完成文本框中的源,如果从第一个选择了一个值。
我的标记片段如下:
$(function () {
$("#SelectedAddress").autocomplete({
source: "/CreateFIS/GetProperties",
select: function(event, ui) {
if (ui.item) {
event.preventDefault();
$('#SelectedAddress').val(ui.item.label);
$('#SelectedAddressId').val(ui.item.value);
getPropertyInformation(ui.item.value);
}
},
focus: function(event, ui) {
if (ui.item) {
event.preventDefault();
$('#SelectedAddress').val(ui.item.label);
$('#SelectedAddressId').val(ui.item.value);
//getPropertyInformation(ui.item.value);
}
}
});
});
$(function () {
$("#SelectedScheme").autocomplete({
source: "/CreateFIS/GetSchemes",
select: function (event, ui) {
if (ui.item) {
event.preventDefault();
$('#SelectedScheme').val(ui.item.label);
$('#SelectedSchemeId').val(ui.item.value);
}
},
focus: function (event, ui) {
if (ui.item) {
event.preventDefault();
$('#SelectedScheme').val(ui.item.label);
$('#SelectedSchemeId').val(ui.item.value);
}
}
});
});
<tr>
<td style="width:200px;"><label for="addresses">Please Select A Scheme</label> </td>
<td style="width:600px;">@Html.TextBoxFor(model => model.SelectedScheme, new { @class = "largeTextBox" })</td>
<td style="width:200px;"> @Html.ValidationMessageFor(model => model.SelectedSchemeId) </td>
</tr>
<tr>
<td style="width:200px;"><label for="addresses">Please Select A Property </label> </td>
<td style="width:600px;">@Html.TextBoxFor(model => model.SelectedAddress, new { @class = "largeTextBox" })</td>
<td style="width:200px;"> @Html.ValidationMessageFor(model => model.SelectedAddressId) </td>
</tr>
什么是实现这个目标的最好方法?
答案 0 :(得分:1)
使用option
方法更改来源:
var source = $(".selector").autocomplete("option", "source", "/New/Source");