简体   繁体   English

包括JQuery库

[英]Including JQuery library

I have the following file organization: 我有以下文件组织:

Project > SubFolder1> SubFolder2> Subfolder3> Test.aspx Project> SubFolder1> SubFolder2> Subfolder3> Test.aspx

and I am trying to include Jquery library from 我试图包括Jquery库

Project> Scripts 项目>脚本

in test page I did both: 在测试页面我做了两个:

<script src="~/Scripts/jquery-1.9.1.js"></script>

and

<script src="../../../Scripts/jquery-1.9.1.js"></script>

but it gives me that the resource cannot be found and the URI in source view is: 但它让我无法找到资源,源视图中的URI是:

localhost:44388/Project/SubFolder1/SubFolder2/SubFolder3/~/Scripts/jquery-1.9.1.js 本地主机:44388 /项目/ SubFolder1 / SubFolder2 / SubFolder3 /〜/脚本/ jQuery的1.9.1.js

How can I include the library correctly? 如何正确包含库?

Try this (without tilde): 试试这个(没有代字号):

<script src="/Scripts/jquery-1.9.1.js"></script>

Or if you are in an ASP.NET MVC context: 或者,如果您在ASP.NET MVC上下文中:

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

I would suggest keeping all the javascript files in a seperate folder in the ROOT folder and name it ' js '. 我建议将所有javascript文件保存在ROOT文件夹中的单独文件夹中,并将其命名为“ js ”。

For ex if your root folder is PROJECTS , then make a new folder ' js ' and paste all you javascript and jquery files in this folder then you can reference this files in this manner 例如,如果您的根文件夹是PROJECTS ,那么创建一个新文件夹' js '并将所有javascript和jquery文件粘贴到此文件夹中,然后您可以这种方式引用这些文件

<script src="js/jquery-1.9.1.js"></script>

我必须像这样包括它

<script src="/Project Name/Scripts/jquery-1.9.1.js"></script>

You could use a CDN for these kind of universally known, general purpose libraries. 您可以将CDN用于这类通用的通用库。

A Content Delivery network gives you the advantage of faster load time, because of the clients will be served by the nearest/fastest server (less network latency), and of course, if the client already visited some other website which also made use of jQuery over the CDN, there's a big chance the file is already in the browsers cache, so no download of the file is actually needed. 内容交付网络为您提供了更快加载时间的优势,因为客户端将由最近/最快的服务器提供服务(减少网络延迟),当然,如果客户端已经访问了其他一些也使用了jQuery的网站在CDN上,文件很可能已经存在于浏览器缓存中,因此实际上不需要下载文件。

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

See http://jquery.com/download/ http://jquery.com/download/

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

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