jQuery库的位置要被服务器引用不同 [英] jQuery library location wants to be referenced differently on server

查看:112
本文介绍了jQuery库的位置要被服务器引用不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经得到了使用jQuery ASP.NET MVC应用程序。要加载JS库,我引用它们是这样的:

I've got an ASP.NET MVC application that uses jQuery. To load the js libraries, I reference them like this:

<script type="text/javascript" src="../../Scripts/jquery-1.3.2.min.js"></script>

这在当地工作正常,但是当我把它发布到服务器,它无法找到库。为了得到它的工作,我必须把它改成这样:

This works fine locally, but when I publish it to the server, it can't find the library. To get it to work, I have to change it to this:

<script type="text/javascript" src="../Scripts/jquery-1.3.2.min.js"></script>

此更改允许它在本地和服务器上运行,但它给了我一个警告,该文件没有被发现。所以,我有几个问题:

Making this change allows it to work locally and on the server, but it gives me a warning that the file was not found. So I've got a couple of questions:


  1. 如何在本地code工作,如果我不引用正确的库位置?

  2. 我可以把为将工作无处不在,不是抛出一个警告?
  3. 脚本路径

我知道的答案,#2是库存储在一些已知的绝对路径,但我不准备提交到呢。

I know an answer to #2 is to store the libraries in some known absolute path, but I'm not ready to commit to that yet.

推荐答案

试试这个:

<script type="text/javascript" src='<%= Url.Content("~/Scripts/jquery-1.3.2.min.js") %>'></script>

这将相对化的路径应用程序的根,无论是否是在顶层或虚拟目录。我实际上已经开发出的HtmlHelper扩展,让打扫一下为:

This will relativize the path to the root of your application regardless of whether it is at the top level or in a virtual directory. I actually developed a HtmlHelper extension that lets clean this up to:

<%= Html.Javascript( Url.Content( "~/Scripts/jquery-1.3.2.min.js" )) %>

添加以下获得智能感知。这需要工作的相对路径,但被排除在运行时因为条件(总是)失败。

Add the following to get intellisense. This needs the relative path to work, but gets excluded at runtime because the condition (always) fails.

<% if (false) { %>
     <script type="text/javascript" src="../../Scripts/jquery-1.3.2.vsdoc.js"></script>
<% } %>

这篇关于jQuery库的位置要被服务器引用不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆