使用Event从自动完成列表中选择后如何显示元素?

时间:2014-05-07 05:25:04

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

我想在从自动完成列表中选择后显示元素。

我的代码:

  $(function () {

                $("#SearchString").autocomplete({
                    messages: '',
                    source: '@Url.Action("GetProducts","Search")',
                    minLength: 2,

                });
          });

<div id="search" style="display:inline">

 @using (Html.BeginForm("SearchProduct", "Search", FormMethod.Post, "null"))
 {

        @Html.TextBox("SearchString", null, new { id = "SearchString" })

        <input type="submit" value="Search" id="Search" />
}

</div>

请分享您的建议。

1 个答案:

答案 0 :(得分:0)

您需要添加select自动填充事件:

$("#SearchString").autocomplete({
                    messages: '',
                    source: '@Url.Action("GetProducts","Search")',
                    minLength: 2,
                    select: function (i, j) 
                    {
                    alert(j.item.value);
                    }

                });

有关详细信息,请参阅自动填充documentation

Fiddle Example HERE

相关问题