Sharepoint无法识别Javascript文件路径

时间:2012-06-07 13:58:29

标签: javascript css sharepoint-2010 sharepoint-designer ascx

我需要从ascx控件访问sharepoint样式库中的css和javascript文件。我在样式lybrary中存储了自定义css和javascript文件,并在ascx中添加了以下代码。但问题是sharepoint 从下面给定的路径中识别javascript文件。

ascx中的代码

<SharePoint:CssLink runat="server" ID="MenuCSSLink" Version="4" ></SharePoint:CssLink>
<SharePoint:CssRegistration Name="/Style Library/en-us/Core Styles/Style.css" EnableCssTheming="True" ID="css" runat="server"></SharePoint:CssRegistration>
<SharePoint:ScriptLink id="ScriptLinkMenu1" runat="server"  Name="~SiteCollection/Style Library/en-us/Core Styles/JS/script1.js " ></SharePoint:ScriptLink>
<SharePoint:ScriptLink id="ScriptLinkMenu2" runat="server"  Name="~SiteCollection/Style Library/en-us/Core Styles/JS/script2.min.js " ></SharePoint:ScriptLink>
<SharePoint:ScriptLink id="ScriptLinkMenu3" runat="server" Name="~SiteCollection/Style Library/en-us/Core Styles/JS/script3.js " ></SharePoint:ScriptLink>
<SharePoint:ScriptLink id="ScriptMenu6" runat="server"  Name="~SiteCollection/Style Library/en-us/Core Styles/JS/script4.js " ></SharePoint:ScriptLink>

我使用IE开发人员工具(F12)测试了该页面,发现css正确渲染但不是js。 我将Java脚本保存在样式库root flder中并进行了测试。这个也没用?

2 个答案:

答案 0 :(得分:2)

JS链接的末尾有一个额外的空间。它正在逃避该空间并向您的网址添加%20。如果您查看源代码,您可能会看到如下内容:

document.write('<script src="/Style%20Library/en-us/Core%20Styles/JS/script1.js%20"></' + 'script>');

删除该空格应指向正确的文件URL。

答案 1 :(得分:0)

我修改了以下代码

<SharePoint:CssLink runat="server" ID="MenuCSSLink" Version="4" DefaultUrl="<% $SPUrl:~SiteCollection/Style Library/en-us/Themable/Style.css %>" ></SharePoint:CssLink>
<SharePoint:CssRegistration Name="/Style Library/en-us/Themable/Style.css" EnableCssTheming="True" ID="css" After="corev4.css" runat="server"></SharePoint:CssRegistration>
<SharePoint:ScriptLink id="ScriptLinkMenu1" runat="server"  Name="~SiteCollection/Style Library/en-us/Core Styles/JS/script1.js" Language="javascript" ></SharePoint:ScriptLink>
<SharePoint:ScriptLink id="ScriptLinkMenu2" runat="server"  Name="~SiteCollection/Style Library/en-us/Core Styles/JS/script2.min.js" Language="javascript" ></SharePoint:ScriptLink>
<SharePoint:ScriptLink id="ScriptLinkMenu3" runat="server" Name="~SiteCollection/Style Library/en-us/Core Styles/JS/script3.js" Language="javascript" ></SharePoint:ScriptLink>
<SharePoint:ScriptLink id="ScriptMenu6" runat="server"  Name="~SiteCollection/Style Library/en-us/Core Styles/JS/script4.js" Language="javascript" ></SharePoint:ScriptLink>

并且为了使主题功能在sharepoint中工作,我将样式表存储在样式库中的可用文件夹中