javascript - 内容编辑器 Web 部件 (CEWP) 中的 JavaScript
问题描述
在 SharePoint 2010 中,我在 newform.aspx 页面中插入了一个 CEWP。如果我直接在 CEWP 中输入代码,它就可以正常工作。如果我将代码放在 SiteAssets 库中并放置相对路径或完整路径,则代码不起作用。
对此的任何帮助将不胜感激。
<script src="https://code.jquery.com/jquery-latest.min.js"></script><script>
function HideFields() {
//Enter the fields you would like to hide here.
fieldsToHide = ["Additional Information Required from Applicant", "Assigned To (Field)", "Date Lands Officer received", "Date Lands Officer started merit review", "External Referral Required", "External Reviewer", "Inspection", "Internal Referral Required", "Internal Reviewer", "Merit Recommendation by Field", "Merit Upload to ECM complete", "Referral Due Date", "Zone", "FNC", "Merit Decision Letter", "Review Merit Recommendation by PAS", "Security"];
//Get all SharePoint fields
var formFieldTitles = $(".ms-formtable td.ms-formlabel h3.ms-standardheader");
//Iterate over each row in the form
formFieldTitles.each(function () {
//Get the text of the field title
var textToMatch = $(this).text();
//Get the table row associated with this title
var currentRow = $(this).closest('tr');
//Iterate over our list of fields we wish to hide
for (var i = 0; i < fieldsToHide.length; i++){
var field = fieldsToHide[i];
//Match the SharePoint field name to our field name
if (textToMatch.toLowerCase().replace("*", "").trim() === field.toLowerCase().replace("*", "").trim()){
//Hide this field
$(currentRow).hide();
}
}
});
}
function AddToBodyOnLoad(){
//Ensure that our function is called last by pushing it again
_spBodyOnLoadFunctionNames.push("HideFields");
}
//Add our function to the array of onload functions
_spBodyOnLoadFunctionNames.push("AddToBodyOnLoad");</script>
解决方案
推荐阅读
- mysql - 在 WHERE 条件中使用 UNION 语句插入选择
- php - 动态更改(或用户更改)Wordpress 中的列数
- typescript - 打字稿检查对象是否可迭代
- angular - 将值设置为没有 NgModel、反应式表单的表单控件?
- python - 来自lxml python的fromstring函数出错
- python - 如何根据阈值在 Python 中对多列进行分组并创建新列
- vue.js - Vue中的迷你枢轴网格,没有外部库
- python - 如何在相当平衡的二元分类中解决非常高的误报率?
- angular - 在组件之间共享变量 angular
- sockets - 将 select 与多个套接字一起使用