C# 如何使用<;asp:scriptreference>;在asp.NET4.5中?
我想在我的web应用程序中包括最新的jquery。 默认情况下,jQuery1.7.1正在加载C# 如何使用<;asp:scriptreference>;在asp.NET4.5中?,c#,javascript,asp.net,scriptmanager,C#,Javascript,Asp.net,Scriptmanager,我想在我的web应用程序中包括最新的jquery。 默认情况下,jQuery1.7.1正在加载 我知道以下代码对此负责。但是我应该如何加载jQuery1.10呢 <asp:ScriptManager runat="server"> <Scripts> <%--To learn more about bundling scripts in ScriptManager see http://go.microsoft.com/f
我知道以下代码对此负责。但是我应该如何加载jQuery1.10呢
<asp:ScriptManager runat="server">
<Scripts>
<%--To learn more about bundling scripts in ScriptManager see http://go.microsoft.com/fwlink/?LinkID=301884 --%>
<%--Framework Scripts--%>
<asp:ScriptReference Name="MsAjaxBundle" />
<asp:ScriptReference Name="jquery" />
<asp:ScriptReference Name="bootstrap" />
<asp:ScriptReference Name="respond" />
<asp:ScriptReference Name="WebForms.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebForms.js" />
<asp:ScriptReference Name="WebUIValidation.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebUIValidation.js" />
<asp:ScriptReference Name="MenuStandards.js" Assembly="System.Web" Path="~/Scripts/WebForms/MenuStandards.js" />
<asp:ScriptReference Name="GridView.js" Assembly="System.Web" Path="~/Scripts/WebForms/GridView.js" />
<asp:ScriptReference Name="DetailsView.js" Assembly="System.Web" Path="~/Scripts/WebForms/DetailsView.js" />
<asp:ScriptReference Name="TreeView.js" Assembly="System.Web" Path="~/Scripts/WebForms/TreeView.js" />
<asp:ScriptReference Name="WebParts.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebParts.js" />
<asp:ScriptReference Name="Focus.js" Assembly="System.Web" Path="~/Scripts/WebForms/Focus.js" />
<asp:ScriptReference Name="WebFormsBundle" />
<%--Site Scripts--%>
</Scripts>
</asp:ScriptManager>
要做到这一点,您必须创建自己的JS包,它通常位于Global.asax或App_Start/BundleConfig.cs中 在这里,你必须添加如下内容,根据版本保持更改,这样可能会有点不同
ScriptManager.ScriptResourceMapping.AddDefinition("jquery", new ScriptResourceDefinition
{
Path = "~/Scripts/jquery-" + str + ".min.js", //your path will be ignored
DebugPath = "~/Scripts/jquery-" + str + ".js", //your path will be ignored
**CdnPath = "http://code.jquery.com/jquery.min.js",**
**CdnDebugPath = "http://code.jquery.com/jquery-latest.js"**,
CdnSupportsSecureConnection = true,
LoadSuccessExpression = "window.jQuery"
});
最后在脚本管理器中启用cdn
<asp:ScriptManager EnableCdn="True" />
可能看起来有点复杂,但一旦设置,它就可以正常工作。不确定
jquery
包是否会自动更新。为什么不使用Nuget jQuery包并使用它进行管理?当我们想要升级时,最好手动更新javascript库。添加更新版本的jquery并不更好,因为方法的某些函数已从以前的版本中删除,如果在代码中使用相同的函数,则必须自己处理。像$.broswer一样,已从较新版本的jquery中删除。您不能使用jquery版本的cdn路径,而是必须移动到最新版本,因为某些插件无法正常工作。据我所知,我没有使用过与jquery版本冲突的函数。简而言之,使用最新的Jquery是我唯一的选择