问题
I have a simple ASP.Net 4.0 website that uses a master page that I would like to include JqueryUI. The Head looks like this.
<head runat="server">
<title></title>
<link href="~/css/Main.css" rel="stylesheet" type="text/css" />
<script src="js/jquery-1.6.2.min.js" type="text/javascript"></script>
<script src="js/jquery-ui-1.8.16.custom/js/jquery-ui-1.8.16.custom.min.js" type="text/javascript"></script>
<link href="js/jquery-ui-1.8.16.custom/css/cupertino/jquery-ui-1.8.16.custom.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
$(function () {
$("#accordion").accordion();
});
</script>
<asp:ContentPlaceHolder ID="HeadContent" runat="server">
</asp:ContentPlaceHolder>
Everything works fine for content pages that inherit from the Master Page as long as it is in the same directory. So if the content page is /Home.aspx alls good, but if it is /Sales/Home.aspx the the styles are never applied to the accordion that is desfined n the Master Page.
回答1:
By using ... "js/jquery-ui-1.8.16.custom/ .. you're redirecting to the JS folder, relativily (is that a word?) to the folder of the current page. If that's in Sales/..., it's looking for the JS-folder in Sales/ but it probably isn't there. You can prevent this by using an absolute link to the root:
<script src="/js/jquery-1.6.2.min.js" type="text/javascript"></script>
This way it will look for the JS folder in the root of the site.
来源:https://stackoverflow.com/questions/8417641/how-to-get-jqueryui-to-work-with-asp-net-master-pages-and-multiple-paths