实施jQuery插件在Visual Studio 2013项目 [英] Implement jQuery Plugin in Visual Studio 2013 Project

查看:411
本文介绍了实施jQuery插件在Visual Studio 2013项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Visual Studio 2013在默认情况下安装此jQuery的-1.10.2.js创建一个新的ASP.NET Web窗体项目。

I created a new ASP.NET Web Forms project in Visual Studio 2013. This installed jquery-1.10.2.js by default.

我使用的软件包管理器控制台安装封装的jQuery -Version 1.11.2
因为管理的NuGet默认情况下只提供的NuGet 2.1.3包。我需要早期的jQuery。

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. I needed the earlier jQuery.

我一直使用VS 2010,和我完全不熟悉的新ASP.NET 4.5的ScriptManager。与2010年的VS jQuery插件,您只需简单地引用的.js和.css在母版页的head部分。

I have been using VS 2010, and I'm completely not familiar with the new 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.

<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的实施,在头部分的脚本标签中不能简单地引用

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.

我的谷歌的研究:在Visual Studio 2013的Web表单安装jQuery插件
有一个处理发现的问题:的NuGet包管理器,安装了jQuery,或Visual Studio扩展。

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.

我还没有发现任何东西,清楚地说明了如何第三方jQuery插件添加到的ASP.NET Web使用Visual Studio 2013窗体应用程序

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.

下面是VS 2013中我的新创建的母版页的JS引用:

Here are the js references in my newly created Master Page in VS 2013:

     <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

This new VS 2013 Web Form Project also has: packages.config, references.js, BundleConfig.cs

我真的AP preciate你的指导。

I would really appreciate your guidance.

推荐答案

我通常在/ App_Start文件夹BundleConfig.cs根据自己的包添加自定义脚本如下:

I usually add custom scripts in their own bundle under BundleConfig.cs in the /App_Start folder as follows:

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

然后,你可以参考束中的ScriptManager在母版页(jQuery的的ScriptReference之后)是这样的:

Then you can reference the bundle in the ScriptManager in your Master Page (after the jQuery ScriptReference) like this:

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

这使您可以使用不同的.js文件进行调试与生产。如果你只有一个脚本版本,那么我相信你可以简单地忽略DebugPath线。

This allows you to use different .js files for debugging vs production. If you only have one script version, then I believe you can simply omit the DebugPath line.

如果插件需要增加的任何CSS文件,它们可以被添加到Bundle.config如下:

If the plugin requires the addition of any CSS files, they can be added to Bundle.config as follows:

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

这篇关于实施jQuery插件在Visual Studio 2013项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆