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