javascript 如何将 Jquery 添加到 MasterPage 2013

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25305168/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 04:20:33  来源:igfitidea点击:

How to add Jquery to MasterPage 2013

javascriptjquerysharepointsharepoint-2013

提问by AdrianX

I'm trying to add jQuery to sharepoint 2013 master page. What I did:

我正在尝试将 jQuery 添加到 sharepoint 2013 母版页。我做了什么:

1)

1)

  • Copy jquery - "jquery-1.11.1.min.js" to C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\TEMPLATE\LAYOUTS.
  • Copy seattle.html and add <!--SPM:<SharePoint:ScriptLink language="javascript" name="/_layouts/jquery-1.11.1.min.js" runat="server" Localizable="false" />-->
  • Upload seattle.html as ASP NET MASTERPAGE
  • Publish it ---> Nothing happend. To seattle.master wasn't appear Sharepoint:Scriptlink
  • 将 jquery - "jquery-1.11.1.min.js" 复制到 C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\TEMPLATE\LAYOUTS。
  • 复制 seattle.html 并添加 <!--SPM:<SharePoint:ScriptLink language="javascript" name="/_layouts/jquery-1.11.1.min.js" runat="server" Localizable="false" />-->
  • 将 seattle.html 上传为 ASP NET MASTERPAGE
  • 发布它 ---> 什么也没发生。到 seattle.master 没有出现 Sharepoint:Scriptlink

2)

2)

  • Copy jquery - "jquery-1.11.1.min.js" to SiteAssets. My application is on root site collection so for instance access to jquery is
  • 将 jquery - "jquery-1.11.1.min.js" 复制到 SiteAssets。我的应用程序在根网站集上,因此例如对 jquery 的访问是

http://localhost/SiteAssets/jquery-1.11.1.min.js

http://localhost/SiteAssets/jquery-1.11.1.min.js

  • Copy seattle.html
    • Add !--SPM:<SharePoint:ScriptLink language="javascript" name="'~sitecollection/SiteAssets/jquery-1.11.1.min.js" runat="server" Localizable="false" />-->
    • Still no effect
  • 复制seattle.html
    • 添加 !--SPM:<SharePoint:ScriptLink language="javascript" name="'~sitecollection/SiteAssets/jquery-1.11.1.min.js" runat="server" Localizable="false" />-->
    • 还是没有效果

What is the correct way from begining to the add of adding Jquery to Sharepoint 2013?

从开始到添加 Jquery 到 Sharepoint 2013 的正确方法是什么?

回答by Vadim Gremyachev

Probably you forgot to apply custom master page, go to Master Page settings page and set Site Master Pageand System Master Pageto your custom master page.

也许你忘了应用自定义母版页,进入母版页设置页面,设置Site Master PageSystem Master Page您的自定义母版页。

Note: there is a typo in the second option: name attribute contains 'symbol

注意:第二个选项有一个错字:name 属性包含 '符号

How to reference JavaScript file in SharePoint 2013 master page

如何在 SharePoint 2013 母版页中引用 JavaScript 文件

Assume the following scenario:

假设以下场景:

  • a custom master page helsinki.masterwith associated HTML file are used
  • jQuery library jquery.min.jsis located in SharePoint Site Assetslibrary
  • 使用helsinki.master带有关联 HTML 文件的自定义母版页
  • jQuery 库jquery.min.js位于 SharePointSite Assets库中

Then, in order to reference jQuery library in custom master page the following steps are used:

然后,为了在自定义母版页中引用 jQuery 库,使用以下步骤:

  • Open an associated HTML file helsinki.html
  • Insert the line <!--SPM:<SharePoint:ScriptLink language="javascript" name="~sitecollection/SiteAssets/jquery.min.js" runat="server" Localizable="false"/>-->
  • Publish helsinki.html
  • Go to Master Page settings page and set Site Master Pageand System Master Pageto helsinki.master
  • 打开关联的 HTML 文件 helsinki.html
  • 插入行 <!--SPM:<SharePoint:ScriptLink language="javascript" name="~sitecollection/SiteAssets/jquery.min.js" runat="server" Localizable="false"/>-->
  • 发布 helsinki.html
  • 进入母版页设置页面并设置Site Master PageSystem Master Pagehelsinki.master

About System Master Page

关于系统母版页

System Master Page is used by administrative pages, lists, and document library views on this site

系统母版页由该站点上的管理页面、列表和文档库视图使用

This approach has been tested in SharePoint 2013 and works for me.

此方法已在 SharePoint 2013 中进行了测试,对我有用。

回答by benniz

i would suggest to add jQuery with a custom DelegateControl. With this approach there is no need to modify the MasterPage. Every Masterpage contains a placeholder where you are able to hook in custom scripts, like jQuery.

我建议添加带有自定义 DelegateControl 的 jQuery。使用这种方法不需要修改 MasterPage。每个 Masterpage 都包含一个占位符,您可以在其中挂钩自定义脚本,例如 jQuery。

Here is a detailed description how to develop the solution: http://blogs.msdn.com/b/kaevans/archive/2011/04/06/adding-jquery-to-every-page-in-sharepoint-with-delegate-controls.aspx

下面是如何开发解决方案的详细说明:http: //blogs.msdn.com/b/kaevans/archive/2011/04/06/adding-jquery-to-every-page-in-sharepoint-with-delegate -controls.aspx

The cool thing with the delegateControl is, that you can use any scopes for this Solution. So you can apply jQuery to the whole Farm, Webapplication, Sitecollection or Web.

delegateControl 很酷的一点是,您可以为此解决方案使用任何范围。因此,您可以将 jQuery 应用于整个 Farm、Web 应用程序、Sitecollection 或 Web。

Regards

问候