如何检测所有文档库Web部件并使用CSS或JavaScript执行某些操作 [英] How to detect all document library web parts and do something with CSS or JavaScript

查看:61
本文介绍了如何检测所有文档库Web部件并使用CSS或JavaScript执行某些操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我想将某些CSS / JavaScript应用于网站集中的所有文档库。例如,我想在每个文档库的顶部添加一个横幅,以获取一些信息性的措辞。

I'd like to apply certain CSS/JavaScript to ALL Document libraries within the site collection. For example, I'd like to add a banner on the top of every document library for some informational verbiage.


我认为这或许应该在全局应用的.master文件。但是,我很难找到一个可以指向页面上所有文档库Web部件的探测器/抓取器。是否有任何唯一标识符,例如
为"Id ="; "类= QUOT;或其他我可以使用CSS / JavaScript来识别Web部件是文档库并对其做些什么的属性?

I figured this perhaps should be done within the .master file as it is being applied globally. However, I'm having a hard time finding a detector/grabber that could pin point all the document library web parts on the page. Is there any unique identifiers such as "Id=" "Class=" or other properties that I could have CSS/JavaScript to recognize that the web part is a document library and do something about it?


请注意以下两个条件该解决方案也应该能够克服 -

Please note the two following conditions that the solution should also be able to overcome -




  1. 区分文档库v.s.通用列表,虽然它们在很多方面呈现类似。

  1. Make distinction between Document library v.s. Generic List, although they rendered similar in many ways.


它应该在文档库中工作是在自己的aspx页面上,或者作为Web部件添加到另一个页面的区域。

It should work when the document library is either on its own aspx page or gets added to a zone of another page as a web part.

推荐答案

文档库将包含文本"或在此处拖动文件"。在New Item td html元素中,如下面的捕获,通用列表将不具有,因此这是一个区分它是文档库还是通用列表的选项:

A document library will contain a text "or drag files here" in New Item td html element like capture below, which Generic List will not have, so this is a option to distinguish if it is a document library or Generic List:

通用列表html元素通过开发人员工具:

Generic List html element through Developer Tool:

通过开发者工具Libray html元素:

Libray html Element through Developer Tool:

然后可以使用下面的Jquery片段来获取文档库选择器:

Then could use the Jquery snippet below to get Document Library selector:

<script type="text/javascript" src="https://code.jquery.com/jquery-3.4.0.min.js"></script>
<script type="text/javascript">


(function(){

console.log(
(function() { console.log(


(" td.ms-list-addnew:contains('或在此处拖动文件')"));

});
< / script>
("td.ms-list-addnew:contains(' or drag files here')")); }); </script>

谢谢

最好的问候


这篇关于如何检测所有文档库Web部件并使用CSS或JavaScript执行某些操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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