我尝试根据 SharePoint 列表中的条件(其他字段中的值)隐藏编辑表单中的字段。下面的代码用于隐藏字段,但逻辑现在不起作用。使用 alert 我可以看到在该字段中选择的不同值,但条件语句没有像我预期的那样将 fldList 重置为空。对此的任何帮助将不胜感激。我是 JS 新手。
<script src="https://code.jquery.com/jquery-latest.min.js"></script><script>
function HideFields() {
//Enter the fields you would like to hide here.
fieldsToHide = fldList;
//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");
}
$(document).ready(function () {
var value = $("select[title='Activity Type Required Field'] option:selected").text();
if (value = 'New'){
fldList = ["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"];
}
else if (value = 'Renewal'){
fldList = [];
}
else{
fldList = [];
}
});
//Add our function to the array of onload functions
_spBodyOnLoadFunctionNames.push("AddToBodyOnLoad");</script>