简体   繁体   English

在我的ASP.Net应用程序中找不到Javascript

[英]Javascript not found in my ASP.Net Application

I am having a problem in the location of my javascript, the location is right, but when I run it in my visual web developer 2010 express, the location can not be found, I don't know the reason why... 我的javascript位置有问题,位置是对的,但是当我在我的可视化开发人员2010快递中运行它时,找不到位置,我不知道为什么...

here is the location of my javascript: 这是我的javascript的位置:

<script src="Style/javascript/jquery-1.7.1.js" type="text/javascript"></script>

here is the error: 这是错误:

**Server Error in '/Maitenance' Application.**

**The resource cannot be found.**

**Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable.  Please review the following URL and make sure that it is spelled correctly.** 

**Requested URL: /Maitenance/Maintenance/Style/javascript/jquery-1.7.1.js**

I guess you are using a master page and your .aspx page is put in another directory. 我猜您使用的是母版页,而您的.aspx页面则放在另一个目录中。 The file path you included in master page is relative to the .aspx file. 您在母版页中包含的文件路径是相对于.aspx文件的。 It works OK when your page in the same directory with the master page. 当您的页面与母版页在同一目录中时,它可以正常工作。

You can include your js file using ResolveUrl: 您可以使用ResolveUrl包含您的js文件:

<script src="<%=ResolveUrl("~/js/jquery.js")%>" type="text/javascript"></script>

or you can include your script in the code behind of master page: 或者您可以将您的脚本包含在母版页的代码中:

ClientScript.RegisterClientScriptInclude("jquery", ResolveClientUrl("~/js/jquery.js"));

使用它...它会工作

 <script src="<%=Page.ResolveUrl("~")%>Style/javascript/jquery-1.7.1.js" type="text/javascript"</script> 

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

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