尝试向SharePoint显示表单添加文本。当前仅能添加到“编辑和新建表单”

问题描述 投票:0回答:1

我正在添加一些JS库,以允许SharePoint网站的所有者通过引用资产库中的各种脚本为其表单和页面添加一些功能。我有一个脚本,允许用户在EditForm和NewForm中的任何字段上方插入Section标题。

但是,这不适用于DispForm。用户将对脚本的引用放置在“脚本编辑器”中,并传递参数(“ Section Heading and Field”(在前面插入标题)。我的引用如下:

<script type="text/javascript" data-color="" data-sections="Add New UID Anomally-UID" src="../../SiteAssets/js-enterprise/AddSections.js"></script>

我在SiteAssets中的实际脚本是:

$(document).ready(function() {  
  // Get a list of views to turn off the headers
  var this_js_script = $('script[src*=AddSections]');
  var lists = this_js_script.attr('data-sections'); 
  var str_array = lists.split(',');

  var color = this_js_script.attr('data-color'); 
  // over-ride color if there is no value #96c03d
  if (typeof color == 'undefined' || color == null || color == ''){
    color = "#000000";
  }

  for(var n = 0; n < str_array.length; n++) {
    // Trim the excess whitespace.
    str_array[n] = str_array[n].replace(/^\s*/, "").replace(/\s*$/, "");
    // Add additional code here, such as:
    var str2_array = str_array[n].split('-');
    AddSectionBeforeField(str2_array[0],str2_array[1],color);
  }
});

function AddSectionBeforeField(sectionText,fieldName,colorcode){
  var $fieldTR=$(".ms-standardheader nobr:contains('"+fieldName+"')").closest("tr");
  $fieldTR.before("<tr style='background-color:white'><td colspan='2' class='ms-formbody' style='padding:0; color: "+colorcode+";'><div style='font-size:22px;margin-top: 10px;margin-bottom: 10px;font-family: Oswald';'>"+sectionText+"</div></td></tr>");
}

我该如何使两者兼而有之或将其更改为适用于DispForm?

javascript sharepoint-2013
1个回答
0
投票

编辑表单和显示表单不同。

enter image description here

enter image description here

因此您需要对不同的表单使用不同的选择器。

在显示形式的jQuery选择器下面。

 $("h3.ms-standardheader:contains('Current Route Date')");
© www.soinside.com 2019 - 2024. All rights reserved.