简体   繁体   English

在Visual Studio 2013项目中实现jQuery插件

[英]Implement jQuery Plugin in Visual Studio 2013 Project

I created a new ASP.NET Web Forms project in Visual Studio 2013. This installed jquery-1.10.2.js by default. 我在Visual Studio 2013中创建了一个新的ASP.NET Web窗体项目。默认情况下会安装jquery-1.10.2.js。

I used the Package Manager Console to Install-Package jQuery -Version 1.11.2 because the Manage Nuget Packages only offered Nuget 2.1.3 by default. 我使用软件包管理器控制台安装jQuery版本1.11.2,因为默认情况下“管理Nuget软件包”仅提供Nuget 2.1.3。 I needed the earlier jQuery. 我需要早期的jQuery。

I have been using VS 2010, and I'm completely not familiar with the new ASP.NET 4.5 ScriptManager. 我一直在使用VS 2010,但对新的ASP.NET 4.5 ScriptManager完全不熟悉。 With VS 2010 for jQuery Plugins, you simply reference the .js and .css in the head section of the Master Page. 使用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>

With ASP.NET 4.5 I'm a little unclear about how to add a 3rd party jQuery Plugin, because it appears that all of the .js files are implemented via the ScriptManager, not simply referenced within script tags in the head section. 使用ASP.NET 4.5时,我不清楚如何添加第三方jQuery插件,因为似乎所有的.js文件都是通过ScriptManager实现的,而不是在开头的script标签中简单引用的。

My Google research: "install jquery plugin in visual studio 2013 web form" has found issues dealing with: the Nuget Package Manager, Installing jQuery, or Visual Studio Extensions. 我的Google研究发现:“在Visual Studio 2013 Web表单中安装jquery插件”发现了以下问题:Nuget软件包管理器,安装jQuery或Visual Studio扩展。

I haven't found anything that clearly explains how to add 3rd party jQuery Plugins to the ASP.NET Web Forms application with Visual Studio 2013. 我还没有发现任何能清楚说明如何使用Visual Studio 2013将第三方jQuery插件添加到ASP.NET Web窗体应用程序的内容。

Here are the js references in my newly created Master Page in VS 2013: 这是我在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>

This new VS 2013 Web Form Project also has: packages.config, references.js, BundleConfig.cs 这个新的VS 2013 Web表单项目还具有:packages.config,references.js,BundleConfig.cs

I would really appreciate your guidance. 非常感谢您的指导。

I usually add custom scripts in their own bundle under BundleConfig.cs in the /App_Start folder as follows: 我通常将自定义脚本添加到/ App_Start文件夹中BundleConfig.cs下自己的捆绑中,如下所示:

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

Then you can reference the bundle in the ScriptManager in your Master Page (after the jQuery ScriptReference) like this: 然后,您可以在母版页(在jQuery ScriptReference之后)的ScriptManager中引用捆绑软件,如下所示:

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

This allows you to use different .js files for debugging vs production. 这使您可以使用不同的.js文件进行调试和生产。 If you only have one script version, then I believe you can simply omit the DebugPath line. 如果您只有一个脚本版本,那么我相信您可以省略DebugPath行。

If the plugin requires the addition of any CSS files, they can be added to Bundle.config as follows: 如果插件需要添加任何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.

相关问题 Visual Studio 2013 MVC-jQuery Datepicker - Visual Studio 2013 MVC - jquery datepicker jQuery intellisense插件现在可用于Visual Studio吗? - Is the jQuery intellisense plugin available for Visual Studio now? 在Visual Studio中安装DataTable Jquery插件 - Install DataTable Jquery Plugin in Visual Studio Visual Studio 插件中的 jquery 数据表不起作用 - jquery datatable in visual studio plugin not working Visual Studio 2013 Update 5和带有jQuery DefinitelyTyped的Typescript导致编译错误 - Visual Studio 2013 Update 5 and Typescript with jQuery DefinitelyTyped results in compilation errors 如何在angular2项目中将Jquery插件实现为外部文件? - How to implement Jquery plugin as external file in angular2 project? jQuery插件-BlockUI-在Visual Studio中工作异常吗? - JQuery plugin - BlockUI - works strangely from Visual Studio? Visual Studio 2017 react/redux 项目中的 Bootstrap 错误“未定义 jQuery” - Bootstrap error "jQuery is not defined" in Visual Studio 2017 react/redux project 将jquery添加到visual studio中的“空”Web项目的最佳方法? - best way to add jquery to an “empty” web project in visual studio? JQuery Visual Diff插件 - JQuery Visual Diff Plugin
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM