2

我的表单上有 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>

实现这一目标的最佳方法是什么?

4

1 回答 1

1

使用option方法更改源:

var source = $(".selector").autocomplete("option", "source", "/New/Source");
于 2012-05-31T13:39:45.130 回答