문제

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