I'm playing around with ASP.NET and jquery in an attempt to learn it, and right now I'm working on an autocomplete textbox, but with little luck. I've been following this tutorial and the example code on the jqueryui page, but something isn't working right. I've installed both jquery and jquery-ui using NuGet.

This is the code I've tried, any obvious problems?

<script src="Scripts/jquery-2.1.0.js" type="text/javascript"></script>
<script src="Scripts/jquery-ui-1.10.4.js" type="text/javascript"></script>
<link rel="stylesheet" href="~/Content/themes/base/jquery-ui.css" type="text/css" />

<script type="text/javascript">
    $(document).ready(function () {
        $("input#TextBoxAutoComplete").autocomplete({
            source: ["c++", "java", "php", "coldfusion", "javascript", "asp", "ruby"]
        });
    })
</script>

<br />
<asp:TextBox ID="TextBoxAutoComplete" ClientIDMode="Static" runat="server"></asp:TextBox>
<br />
有帮助吗?

解决方案

Based on the comments

  1. Include the jQuery-ui.css file
  2. Check the generated input element's id... use a static id if required
  3. Check whether the path to the script/style files are correct

其他提示

Try to use:

$('#<%= TextBoxAutoComplete.ClientID %>').autocomplete({...

or:

$('[id$=TextBoxAutoComplete]').autocomplete({...

instead of:

$("input#TextBoxAutoComplete").autocomplete({...
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top