选择事件上的Jquery autocomplete-combobox。 ASP。净mvc 5

时间:2015-11-06 17:27:32

标签: jquery asp.net asp.net-mvc combobox jquery-ui-autocomplete

我的观点中有多个自动完成组合框:

        @Html.LabelFor(model => model.foo)
        @Html.DropDownListFor(model => model.foo, Model.ColaboradoresSelectListItem, "--- Select One Item---", new { @class = "autocomplete-combobox" @id = "foo"})
        @Html.ValidationMessageFor(model => model.foo, String.Empty)

        @Html.LabelFor(model => model.foo2)
        @Html.DropDownListFor(model => model.foo2, Model.ColaboradoresSelectListItem, "--- Select One Item---", new { @class = "autocomplete-combobox" @id = "foo2" })
        @Html.ValidationMessageFor(model => model.foo, String.Empty)

我需要选择一个项目,然后我需要的是开始一个事件,到目前为止我已经尝试过了:

    $("#foo").autocomplete({
        select: function (event, ui) { }
    });

    $("#foo").on("autocompleteselect", function (event, ui) {
        alert("Tell me, tell me, tell me now!!!");
    });

    $("#aeroportos").change(function() {
        //$.getJSON("/Home/States/List/" + $("#Countries > option:selected").attr("value"), function (data) {
        //    var items = "<option>---------------------</option>";
        //    $.each(data, function (i, state) {
        //        items += "<option value='" + state.Value + "'>" + state.Text + "</option>";
        //    });
        //    $("#States").html(items);
        //});
        alert("Tried that too");
    });

有什么建议吗?

1 个答案:

答案 0 :(得分:0)

试试这个。 http://jsfiddle.net/andrewwhitaker/hAM9H/

select: function( event, ui ) {
ui.item.option.selected = true;
self._trigger( "selected", event, {
    item: ui.item.option
});
select.trigger("change");                            

},

然后

$(".cmbBox").change(function() {
alert(this.value);});