我正在使用C#和VS 2012中的.NET框架4.5构建一个ASP.NET Webform应用程序。
我在应用程序的根目录中有一个MasterPage,在名为js的文件夹中有JavaScript文件。
问题在于:如果页面在根文件夹中,那么一切都正常工作(css + js),但如果我将任何页面放在子文件夹中,则css可以正常工作,但那些JavaScript根本不起作用,显然引用路径是错误的。
因此,Css的引用路径没有问题,但对于脚本来说,无论我使用什么方法(如js / script.js或〜/ js / script.js或/ js / script.js或../ ResolveUrl,ResolClientveUrl ... 或在这个http://yobriefca.se/blog/2010/10/19/%3C-head-%3Eache-including-javascript-in-asp-dot-net-master-pages/中提到的所有方法),它们都会引用root / SUB-FOLDER / js / script.js而不是root / js / script.js。
在我的MasterPage中:
<head runat="server">
<title></title>
<link rel="stylesheet" href="~/css/style.css" />
<%-- tried these and lot more but NOT workkkkkkkkkkk --%>
<%--<script src="~/js/jquery-1.7.1.min.js" ></script>
<script src="~/js/script.js" ></script>--%>
<%--<script src='<%=ResolveUrl("~/js/jquery-1.7.1.min.js") %>' ></script>
<script src='<%=ResolveUrl("~/js/script.js") %>' type="text/javascript"></script>--%>
<%--<script src='<%=ResolveClientUrl("~/js/jquery-1.7.1.min.js") %>' type="text/javascript"></script>
<script src='<%=ResolveClientUrl("~/js/script.js") %>' type="text/javascript"></script>--%>
<asp:ContentPlaceHolder ID="Head" runat="server">
</asp:ContentPlaceHolder>
....
$.include('js/superfish.js')
$.include('js/FF-cash.js')
$.include('js/tms-0.4.x.js')
$.include('js/uCarausel.js')
$.include('js/jquery.easing.1.3.js')
$.include('js/jquery.tools.min.js')
$.include('js/jquery.jqtransform.js')
$.include('js/jquery.quicksand.js')
$.include('js/jquery.snippet.min.js')
$.include('js/jquery-ui-1.8.17.custom.min.js')
$.include('js/jquery.cycle.all.min.js')
$.include('js/jquery.cookie.js')
$(function(){
if($('.tweet').length)$.include('js/jquery.tweet.js');
if($('.lightbox-image').length)$.include('js/jquery.prettyPhoto.js');
if($('#contact-form').length||$('#contact-form2').length)$.include('js/forms.js');
if($('.kwicks').length)$.include('js/kwicks-1.5.1.pack.js');
if($('#counter').length)$.include('js/jquery.countdown.js');
if($('.fixedtip').length||$('.clicktip').length||$('.normaltip').length)$.include('js/jquery.atooltip.pack.js')
// Slider
$('.main-slider')._TMS({
.....
网页浏览器的开发工具(控制台)中出现错误:
Failed to load resource: the server responded with a status of 404 (Not Found) http://ApplicationRoot/Pages/js/tms-0.4.x.js
Failed to load resource: the server responded with a status of 404 (Not Found) http://ApplicationRoot/Pages/js/uCarausel.js
Failed to load resource: the server responded with a status of 404 (Not Found) http://ApplicationRoot/Pages/js/jquery.jqtransform.js
Failed to load resource: the server responded with a status of 404 (Not Found) http://ApplicationRoot/Pages/js/jquery.quicksand.js
Failed to load resource: the server responded with a status of 404 (Not Found) http://ApplicationRoot/Pages/js/jquery.snippet.min.js
Failed to load resource: the server responded with a status of 404 (Not Found) http://ApplicationRoot/Pages/js/FF-cash.js
Failed to load resource: the server responded with a status of 404 (Not Found) http://ApplicationRoot/Pages/js/superfish.js
Failed to load resource: the server responded with a status of 404 (Not Found) http://ApplicationRoot/Pages/js/jquery.tools.min.js
Failed to load resource: the server responded with a status of 404 (Not Found) http://ApplicationRoot/Pages/js/jquery-ui-1.8.17.custom.min.js
Failed to load resource: the server responded with a status of 404 (Not Found) http://ApplicationRoot/Pages/js/jquery.cycle.all.min.js
Failed to load resource: the server responded with a status of 404 (Not Found) http://ApplicationRoot/Pages/js/jquery.easing.1.3.js
Failed to load resource: the server responded with a status of 404 (Not Found) http://ApplicationRoot/Pages/js/jquery.cookie.js
Uncaught TypeError: Object [object Object] has no method '_TMS' script.js:22
event.returnValue is deprecated. Please use the standard event.preventDefault() instead.
~/
。因为脚本不是 ASP.NET 控件,它会按原样添加到最终的 HTML 中,浏览器无法识别~/
。 - Givi<%-- --%>
- Givi