简体   繁体   English

jQuery自动完成功能可在Jsfiddle上使用,但不能在页面上使用

[英]Jquery autocomplete works on Jsfiddle but not on the page

I have little problem. 我没什么问题 I can't force jquery autocomplete to work. 我不能强迫jquery自动完成工作。 When I put the code on the jsfiddle everything works. 当我将代码放在jsfiddle上时,一切正常。 But when started from my Visual Studio 2013 it doesn't. 但是从我的Visual Studio 2013启动时就没有。

Below is my code: 下面是我的代码:

<input id="seed_one" type="text" name="seed_one" />
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        var data = ["Boston Celtics", "Chicago Bulls", "Miami Heat", "Orlando Magic", "Atlanta Hawks", "Philadelphia Sixers", "New York Knicks", "Indiana Pacers", "Charlotte Bobcats", "Milwaukee Bucks", "Detroit Pistons", "New Jersey Nets", "Toronto Raptors", "Washington Wizards", "Cleveland Cavaliers"];
        $("#seed_one").autocomplete({ source: data });
    });
</script>

Here you can see it on the jsfiddle: http://jsfiddle.net/8w6fF/ 在这里,您可以在jsfiddle上看到它: http : //jsfiddle.net/8w6fF/

Can anyone explain my what I'm doing wrong? 谁能解释我在做什么错?

2 errors I'm getting: 我收到2个错误:

Uncaught ReferenceError: jQuery is not defined Uncaught TypeError object [Object object] has no method autocomplete. 未捕获的ReferenceError:未定义jQuery未捕获的TypeError对象[Object object]没有方法自动完成。

u cannot use links like this 你不能使用这样的链接

    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.js"></script>

u must download the jquery and save it in a folder in your project and then link it to your page..!! 您必须下载jquery并将其保存在项目中的文件夹中,然后将其链接到页面。 the option you used will only work with using internet..!! 您使用的选项仅在使用互联网时有效。

and your stylesheet too..!! 还有你的样式表.. !!

<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">

as Sajad pointed out you should download the jquery and css and save in a folder, but as long as you are using internet its okay. 正如Sajad所指出的,您应该下载jquery和css并保存在一个文件夹中,但是只要您使用Internet就可以了。

The main problem with your code is that you are using old version of jquery-ui. 代码的主要问题是您正在使用旧版本的jquery-ui。

use - http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.js 使用http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.js

so you final code will look like 所以你最终的代码看起来像

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.js"></script>

I Tried The code on my Local browser - 我在本地浏览器上尝试过代码-

<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>

I am very sure that you are NOT INCLUDING "jquery-ui.js" That is the reason you are unable to observe the same result. 我非常确定您没有包含“ jquery-ui.js”,这就是您无法观察到相同结果的原因。

Include the "jquery-ui.js" source and i am 100% sure that your page works :) 包括“ jquery-ui.js”源代码,我100%确定您的页面有效:)

In jsfiddle you are using jQuery UI version 1.9.2, but in your local you are uasing version 1.8.9. 在jsfiddle中,您使用的是jQuery UI版本1.9.2,但在本地使用的是1.8.9版本。 Try with the latest version. 尝试使用最新版本。 Hope this will work. 希望这会起作用。

Ok I found solution. 好吧,我找到了解决方案。 VS MVC5 adds their own line with include of Jquery and overwrites my include with this code: VS MVC5使用Jquery的include添加了自己的行,并使用以下代码覆盖了我的include:

@Scripts.Render("~/bundles/jquery")
@RenderSection("scripts", required: false)

which can be found in /shared/_layout 可以在/ shared / _layout中找到

Thats why my code wasn't working while working on jsfiddle. 这就是为什么我的代码在使用jsfiddle时无法正常工作的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM