如何在asp.net 4.5中使用<asp:scriptreference>包含最新的Jquery?

juh*_*uhi 5 javascript c# asp.net scriptmanager

我想在我的Web应用程序中包含最新的jquery.Bydefault jquery 1.7.1正在加载.

我知道以下代码对此负责.但我应该怎么做加载jquery 1.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>
Run Code Online (Sandbox Code Playgroud)

Onu*_*pal 10

要做到这一点,你必须创建自己的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"
    }); 
Run Code Online (Sandbox Code Playgroud)

最后为脚本管理器启用cdn

<asp:ScriptManager EnableCdn="True" />
Run Code Online (Sandbox Code Playgroud)

可能看起来有点复杂,但一旦你设置它将工作得很好.