开发者

$("#Name").autocomplete is not a function

When I run this page I see error in firebug

<script type="text/javascript">
$(document).ready(function () {
var url = '/Tag/TagName';
$('#Name').autocomplete(url, {
minChars: 1,
multiple: true,
formatResult: function (row) {
return row[0].replace(/(<.+?>)/gi, '');
}
}).result(function (event, data, formatted) {
alert(!data ? "No match!" : "Selected: " + formatted);
});
})
</script> 

Error is:

$("#Name").autocomplete is not a function 

Also I have in this document

  <title>@ViewBag.Title</title>
    <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Scripts/jquery-1.5开发者_如何学编程.1.min.js")" type="text/javascript"></script>
    <script src=@Url.Content("~/Scripts/jquery-ui-1.8.11.js")" type="text/javascript"></script>

and

 <div class="editor-label">
            @Html.LabelFor(model => model.Name)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Name) @Html.ValidationMessageFor(model => model.Name) 
        </div>

What is the source of this error?

Best regards

EDIT

Non, is

<script src=@Url.Content("~/Scripts/jquery-ui-1.8.11.js")" type="text/javascript"></script>

but I have another error:

$("#Name").autocomplete(url, {minChars: 1, multiple: true, formatResult: function (row) {return row[0].replace(/(<.+?>)/gi, "");}}).result is not a function

If this can help:

every script library binding I have at _Layout.cshtml

_Layout.cshtml


The direct reason is that you don't load the jQuery autocomplete plugin (the error message is pretty clear on that).

The underlying reason is that you are missing the opening quote after src=:

<script src=@Url.Content("~/Scripts/jquery-ui-1.8.11.js")"


It does not appear that you are including the jQuery Autocomplete plugin.

http://docs.jquery.com/Plugins/autocomplete

Edit: There is an autocomplete function included with jQuery UI, which is what you are using here. This function is not the same as the jQuery Autocomplete plugin. It does not work the same way. The code you are using here is referencing that plugin, but the autocomplete function you are calling is the one included with jQuery UI. You should take a look at the jQuery UI autocomplete and if that is not what you need you can include the jQuery Autocomplete plugin script and use that instead, keeping your existing code. Be sure to add the plugin script file after jQuery UI so it doesn't get overwritten or download a new version of jQuery UI with the autocomplete function removed.

jQuery UI Autocomplete http://jqueryui.com/demos/autocomplete/

jQuery Autocomplete plugin http://docs.jquery.com/Plugins/autocomplete

<script type="text/javascript" src="http://dev.jquery.com/view/trunk/plugins/autocomplete/jquery.autocomplete.js"></script>

Example of jQuery UI plugin in action

$( "#Name" ).autocomplete({
    source: url,
    minLength: 1,
    select: function( event, ui ) {
        log( ui.item ?
            "Selected: " + ui.item.value + " aka " + ui.item.id :
            "Nothing selected, input was " + this.value );
    }
});


Did you link the library?:

<script type="text/javascript" src="http://dev.jquery.com/view/trunk/plugins/autocomplete/jquery.autocomplete.js"></script>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜