检测到问题:
网络选项卡中的的请求URL正在向页面中的路径添加附加目录,但由于webform嵌套在解决方案结构中的附加目录中,因此该目录无法正常工作。
主页不会将此附加目录添加到请求URL,因为webform不嵌套在解决方案结构中的附加目录中。
如何在母版页中将其设置为脚本的绝对路径?
原始问题:
我遇到了某些页面无法识别jQuery的问题。我试图弄清楚为什么错误"ReferenceError:$ is not defined“出现在我的控制台中,指的是一些页面中的js文件引用,而不是其他页面。
我的母版页如下:
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs" Inherits="UseSage.SiteMaster" %>
<!DOCTYPE html>
<html class=" js flexbox canvas canvastext webgl no-touch geolocation postmessage websqldatabase indexeddb hashchange history draganddrop websockets rgba hsla multiplebgs backgroundsize borderimage borderradius boxshadow textshadow opacity cssanimations csscolumns cssgradients cssreflections csstransforms csstransforms3d csstransitions fontface generatedcontent video audio localstorage sessionstorage webworkers applicationcache svg inlinesvg smil svgclippaths" lang="en">
<head runat="server">
<meta charset="utf-8" />
<title><%: Page.Title %></title>
<link href="~/Content/Site.css" rel="stylesheet" />
<link href="~/Content/wp-content/themes/sage/favicon.png" rel="shortcut icon" type="image/png" />
<script src="Scripts/jquery-2.1.3.js"></script>
<script src="Scripts/jquery-ui-1.8.24.js"></script>
<script src="Scripts/modernizr-2.6.2.js"></script>
<link href="SageWP/Scripts/wp-content/plugins/styles-with-shortcodes/css/style.css" rel="stylesheet" />
<link href="SageWP/Scripts/wp-content/plugins/styles-with-shortcodes/editorplugin/rh_columns.css" rel="stylesheet" />
<link href="SageWP/Scripts/wp-content/plugins/styles-with-shortcodes/editorplugin/rh_columns_ver=1.0.2.css" rel="stylesheet" />
<link href="SageWP/Scripts/wp-content/plugins/styles-with-shortcodes/js/lightbox_themes_default/jquery.lightbox.css" rel="stylesheet" />
<link href="SageWP/Scripts/wp-content/plugins/Wordpress-seo%20css/adminbar.css" rel="stylesheet" />
<link href="SageWP/Scripts/wp-includes/css/admin-bar.min.css" rel="stylesheet" />
<link href="Content/wp-content/themes/roots/assets/css/app.css" rel="stylesheet" />
<link href="SageWP/Scripts/wp-content/themes/sage/style.css" rel="stylesheet" />
<script src="SageWP/Scripts/wp-content/plugins/styles-with-shortcodes/js/sws_frontend.js"></script>
<script src="SageWP/Scripts/wp-content/themes/roots_assets_js/vendor/modernizr-2.6.2.min.js"></script>
<script src="SageWP/Scripts/wp-content/themes/roots_assets_js/plugins.js"></script>
<script src="SageWP/Scripts/wp-content/themes/sage/assets_js/main.js"></script>
<script src="SageWP/Scripts/wp-includes/js/jquery/admin-bar.min.js"></script>
<asp:PlaceHolder runat="server">
<script src="<%: ResolveUrl("~/Scripts/modernizr-2.6.2.js") %>"></script>
</asp:PlaceHolder>
<meta name="viewport" content="width=device-width" />
<asp:ContentPlaceHolder runat="server" ID="HeadContent" />
</head>
<body>
<%--<form runat="server">--%>
<div>
<header class="banner" role="banner">
<div class="container">
<a class="brand" href="http://www.usesage.com/">
<img src="http://www.usesage.com/wp-content/themes/sage/assets/img/sagex2.png" alt="Sage Technologies" title="Sage Technologies" width="111px" height="40px" />
</a>
<nav class="nav-main" role="navigation">
<ul id="menu-primary-navigation" class="nav nav-pills">
<li class="dropdown menu-about-acos"><a class="dropdown-toggle" href="/About_ACOs/AboutACOs.aspx">About ACOs</a>
<ul class="dropdown-menu">
<li class="desktop-hide menu-about-acos"><a href="/About_ACOs/AboutACOs.aspx">About ACOs</a></li>
<li class="desktop-hide menu-overview"><a href="/About_ACOs/AboutACOs.aspx">Overview</a></li>
<li class="menu-aco-building-blocks"><a href="/About_ACOs/ACOBuildingBlocks.aspx">ACO Building Blocks</a></li>
<li class="menu-ideal-state"><a href="/About_ACOs/IdealState.aspx">Ideal State</a></li>
</ul>
</li>
<li class="dropdown menu-about-us"><a class="dropdown-toggle" href="/About.aspx">About Us</a>
<ul class="dropdown-menu">
<li class="desktop-hide menu-about-us"><a href="/About.aspx">About Us</a></li>
<li class="desktop-hide menu-overview"><a href="/About.aspx">Overview</a></li>
<li class="menu-our-leadership"><a href="/about-us/our-leadership/">Our Leadership</a></li>
<li class="menu-our-clientstestimonials"><a href="/about-us/our-clientstestimonials/">Our Clients/Testimonials</a></li>
<li class="menu-case-studies"><a href="/about-us/case-studies/">Case Studies</a></li>
</ul>
</li>
<li class="dropdown menu-solutions"><a class="dropdown-toggle" href="/Solutions.aspx">Solutions</a>
<ul class="dropdown-menu">
<li class="desktop-hide menu-solutions"><a href="/Solutions.aspx">Solutions</a></li>
<li class="desktop-hide menu-overview"><a href="/Solutions.aspx">Overview</a></li>
<li class="menu-clinical-integration"><a href="/solutions/clinical-integration/">Clinical Integration</a></li>
<li class="menu-case-disease-management"><a href="/solutions/case-disease-management/">Case & Disease Management</a></li>
<li class="menu-population-management"><a href="/solutions/population-management/">Population Management</a></li>
<li class="menu-business-intel-analytics"><a href="/solutions/business-intel-analytics/">Business Intel & Analytics</a></li>
<li class="menu-risk-management"><a href="/solutions/risk-management/">Risk Management</a></li>
<li class="menu-health-services-consultation"><a href="/solutions/health-services-consultation/">Health Services Consultation</a></li>
</ul>
</li>
<li class="dropdown menu-aco-implementation"><a class="dropdown-toggle" href="/ACO_Implementation.aspx">ACO Implementation</a>
<ul class="dropdown-menu">
<li class="desktop-hide menu-aco-implementation"><a href="/ACO_Implementation.aspx">ACO Implementation</a></li>
<li class="desktop-hide menu-overview"><a href="/ACO_Implementation.aspx">Overview</a></li>
<li class="menu-90-days-to-an-aco"><a href="/aco-implementation/90-days-to-an-aco/">90 Days to an ACO</a></li>
<li class="menu-customizable-scalable"><a href="/aco-implementation/customizable-scalable/">Customizable & Scalable</a></li>
<li class="menu-technical-architecture"><a href="/aco-implementation/technical-architecture/">Technical Architecture</a></li>
<li class="menu-symphony-partnership"><a href="/aco-implementation/symphony-partnership/">Symphony Partnership</a></li>
<li class="menu-custom-applications"><a href="/aco-implementation/custom-applications/">Custom Applications</a></li>
</ul>
</li>
<li class="desktop-hide menu-contact-us"><a href="/Contact.aspx">Contact Us</a></li>
<li class="desktop-hide menu-faqs"><a href="/Support.aspx">FAQs</a></li>
<li class="desktop-hide menu-news"><a href="/News.aspx">News</a></li>
<li class="desktop-hide menu-login"><a href="/Login.aspx">Login</a></li>
<li class="desktop-hide active menu-home"><a href="/">Home</a></li>
</ul>
</nav>
<div class="utility">
<ul id="menu-utility-menu" class="utility-menu" style="display: inline-block">
<li class="active menu-home"><a href="/Home.aspx">Home</a></li>
<li class="menu-contact-us"><a href="/Contact.aspx">Contact Us</a></li>
<li class="menu-faqs"><a href="/Support.aspx">FAQs</a></li>
<li class="menu-news"><a href="/News.aspx">News</a></li>
<li class="menu-login"><a href="/Login.aspx">Login</a></li>
<li><a class="doc-link" href="https://www.usesage.com/SageWebsite/FindProvider.aspx" target="_blank">Find a Doctor</a></li>
<li>
<fieldset>
<form role="search" method="get" id="searchform" action="http://www.usesage.com">
<input type="text" value="" name="s" id="s" runat="server" style="height: 19px; width: 150px"/>
<span class="search-submit-container">
<input type="submit" id="searchsubmit" value="" class="btn" style="width:100px;margin:0 auto;display:block;">
</span>
</form>
</fieldset>
</li>
</ul>
</div>
</div>
<a class="mobile-menu-link" href="javascript:void(0)"> </a>
</header>
</div>
<div id="body">
<asp:ContentPlaceHolder runat="server" ID="FeaturedContent" />
</div>
</body>
</html>在一个实例中,jQuery在此页面中不起作用。
HTML格式如下:
<%@ Page Title="Ideal State - Sage" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="IdealState.aspx.cs" Inherits="UseSage.About_ACOs.IdealState" %>
<asp:Content ID="Content2" ContentPlaceHolderID="FeaturedContent" runat="server">
<%--<script src="/PageHelpers/ideal_state.js"></script>--%>
<script type="text/javascript">
$(function () {
$('body').addClass('page page-id-125 page-child parent-pageid-124 ideal-state');
});
</script>
<div class="wrap container" role="document">
<div class="content row">
<div class="main span12" role="main">
<div class="page-header">
...
</div>
<section class="body-content">
...
</section>
<div class="page-footer-banner"></div>
<div class="subnav-container">
<div class="subnav-inner">
<ul>
<li class="page_item page-item-127"><a href="/AboutACOs/ACOBulidingBlocks.aspx">ACO Building Blocks</a></li>
<li class="page_item page-item-636"><a href="/about-acos/download-whitepaper/">Download White Paper</a>
<ul class='children'>
<li class="page_item page-item-638"><a href="/about-acos/download-whitepaper/thank-you/">Thank You</a></li>
</ul>
</li>
<li class="page_item page-item-631"><a href="/About-ACOs/Contact.aspx">Contact Us</a>
<ul class='children'>
<li class="page_item page-item-633"><a href="/about-acos/contact-us/thank-you/">Thank You</a></li>
</ul>
</li>
<li class="page_item page-item-125 current_page_item"><a href="/About_ACOs/IdealState.aspx">Ideal State</a></li>
</ul>
</div>
</div>
</div>
<!-- /.main -->
</div>
<!-- /.content -->
</div>
<!-- /.wrap -->
</asp:Content>在一个实例中,jQuery在此页面中工作正常。
HTML格式如下:
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Home.aspx.cs" Inherits="UseSage.Home" %>
<asp:Content runat="server" ID="FeaturedContent" ContentPlaceHolderID="FeaturedContent">
<script src="PageHelpers/home.js"></script>
<a href="Content/Home/">Content/Home/</a>
<div class="wrap container" role="document">
<div class="content row">
<div class="main span12" role="main">
<h1>Making ACO implementation a dream, not a nightmare.</h1>
<div class="page-title-banner"> </div>
<!-- <div class="page-title-banner"></div> -->
<div class="home-element-container">
<!-- Start the Loop. -->
<article class="home-block">
<div class="text-content">
<h2>Bewilderment is exactly what you don’t need.</h2>
<p>The ceaselessly changing world of health care regulation is confusing enough without our adding to the chaos. Instead, we’re an oasis of order bringing understanding to the process. Payers are asking providers of healthcare to perform administrative – insurance type services and to be at risk for meeting quality and cost requirements.</p>
<button onclick="location.href='/aco-implementation/'">Learn about how we implement ACOs</button>
</div>
<img width="370" height="370" src="/Content/Home/art-1.png" class="attachment-post-thumbnail wp-post-image" alt="Learn about how we implement ACOs">
</article>
<article class="home-block">
<div class="text-content">
<h2>We don’t just talk about getting things done, we actually get them done.</h2>
<p>Some people talk, others do. We fall squarely in the latter camp. Rather than merely spouting the latest buzzwords and catchphrases, we come to work prepared to actually get to work on implementing solutions for all aspects of your business. Payers currently use Sage to help providers meet such requirements as cost efficiency, quality, patient information and regulatory changes.</p>
<button onclick="location.href='/solutions/'">Learn about our solutions</button>
</div>
<img width="401" height="640" src="/Content/Home/art-2.png" class="attachment-post-thumbnail wp-post-image" alt="Learn about our Soultions">
</article>
<article class="home-block">
<div class="text-content">
<h2>The clock is ticking. We help you build an ACO that fits…fast.</h2>
<p>“One size fits all” is great in theory, but a disaster the first time you try on a shoe that’s two sizes too small. The same is true of companies that try to force-fit a solution for your company with no regard for the customization that’s required to really make it right for you. Do you really want a “one size fits all” ACO?</p>
<p>We step into the shoes of what the payer or providers need to get done and implement the Sage toolbox to meet operational and regulatory requirements.</p>
<button onclick="location.href='/about-acos/'">Learn about ACOs</button>
</div>
<img width="235" height="371" src="/Content/Home/art-3.png" class="attachment-post-thumbnail wp-post-image" alt="Learn about ACOs">
</article>
</div>
</div>
<!-- /.main -->
</div>
<!-- /.content -->
</div>
<!-- /.wrap -->
<script type='text/javascript' src='SageWP/Scripts/wp-content/themes/roots_assets_js/plugins.js'></script>
<script type='text/javascript' src='SageWP/Scripts/wp-content/themes/sage/assets_js/main.js'></script>
</asp:Content>发布于 2016-12-29 14:38:46
我也有同样的问题。对于主页,js文件正在工作,但是如果应用程序移动到一些内部页面,它就不工作了。我找到了一个解决方案,请找到下面的代码。如果它对你有效,请投我一票。
<script type="text/ecmascript" src='<%= ResolveUrl("~/js/jquery-2.2.3.min.js") %>'></script>
<script type="text/ecmascript" src='<%= ResolveUrl("~/js/bootstrap.min.js") %>'></script>
<script type="text/ecmascript" src='<%= ResolveUrl("~/js/app.js") %>'></script>发布于 2015-02-14 04:39:59
您需要使脚本路径成为相对路径,以便可以从任何内容页面访问它们,而不管其路径如何。
<script src="~/Scripts/jquery-2.1.3.js"></script>发布于 2015-02-14 05:27:26
您在母版页中使用的文件的路径必须是该文件的路径,因为它将位于使用该母版页的任何页面中。
您需要使用脚本文件的绝对URL,而不是您现在拥有的相对路径。您可以通过多种方式来完成此任务,但最简单的方法可能是将所有客户端<link>和<script>元素转换为服务器端生成的元素。如果你想获得更高级的东西,你可以抓起System.Web.Optimization NuGet并开始使用捆绑包。
"~/"为你提供了一个绝对的起始路径,这个路径也会考虑到你的应用的根目录位置(虚拟根目录),但是只能在ASP.Net处理的url中使用。因此,在页面或代码背后生成HtmlLink,将这些-
<link href="~/Content/Site.css" rel="stylesheet" />变成这样的形式-
<asp:HtmlLink ID="whatever" runat="server" Href="~/Content/Site.css" rel="stylesheet" type="text/css" />或者这个表格-
HtmlLink sheet = new HtmlLink();
sheet.Href = "~/Content/Site.css";
sheet.Attributes.Add("type", "text/css");
sheet.Attributes.Add("rel", "stylesheet");
Page.Header.Controls.Add(sheet);我不认为<script>元素有特定的控件,因为它们希望您使用脚本管理器类,但您可以使用代码后台的通用控件。
<script src="Scripts/jquery-2.1.3.js"></script>转到
HtmlGenericControl jscript = new HtmlGenericControl("script");
jscript.Attributes.Add("src", Server.MapPath("~/Scripts/jquery-2.1.3.js"));
jscript.Attributes.Add("type", "text/javascript");
Page.Header.Controls.Add(jscript);https://stackoverflow.com/questions/28508334
复制相似问题