簡體   English   中英

在Visual Studio 2013項目中實現jQuery插件

[英]Implement jQuery Plugin in Visual Studio 2013 Project

我在Visual Studio 2013中創建了一個新的ASP.NET Web窗體項目。默認情況下會安裝jquery-1.10.2.js。

我使用軟件包管理器控制台安裝jQuery版本1.11.2,因為默認情況下“管理Nuget軟件包”僅提供Nuget 2.1.3。 我需要早期的jQuery。

我一直在使用VS 2010,但對新的ASP.NET 4.5 ScriptManager完全不熟悉。 使用VS 2010 for jQuery插件,您只需在母版頁頭部分引用.js和.css。

<head id="Head1" runat="server">
   <link href="css/colorpicker.css" rel="Stylesheet" type="text/css" />
   <script type="text/javascript" src="js/colorpicker.js"></script>
</head>

使用ASP.NET 4.5時,我不清楚如何添加第三方jQuery插件,因為似乎所有的.js文件都是通過ScriptManager實現的,而不是在開頭的script標簽中簡單引用的。

我的Google研究發現:“在Visual Studio 2013 Web表單中安裝jquery插件”發現了以下問題:Nuget軟件包管理器,安裝jQuery或Visual Studio擴展。

我還沒有發現任何能清楚說明如何使用Visual Studio 2013將第三方jQuery插件添加到ASP.NET Web窗體應用程序的內容。

這是我在VS 2013中新創建的母版頁中的js參考:

     <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>

這個新的VS 2013 Web表單項目還具有:packages.config,references.js,BundleConfig.cs

非常感謝您的指導。

我通常將自定義腳本添加到/ App_Start文件夾中BundleConfig.cs下自己的捆綁中,如下所示:

ScriptManager.ScriptResourceMapping.AddDefinition(
    "my-plugin", new ScriptResourceDefinition {
        Path = "~/Scripts/my-plugin.min.js",
        DebugPath = "~/Scripts/my-plugin.js",
    }
);

然后,您可以在母版頁(在jQuery ScriptReference之后)的ScriptManager中引用捆綁軟件,如下所示:

<asp:ScriptReference Name="my-plugin" />

這使您可以使用不同的.js文件進行調試和生產。 如果您只有一個腳本版本,那么我相信您可以省略DebugPath行。

如果插件需要添加任何CSS文件,則可以將它們添加到Bundle.config中,如下所示:

<?xml version="1.0" encoding="utf-8" ?>
<bundles version="1.0">
  <styleBundle path="~/Content/css">
    <!-- ...other files likely included here -->
    <include path="~/Content/my-plugin.css" />
  </styleBundle>
</bundles>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM