我正在尝试根据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>发布于 2019-02-25 13:09:32
如果你试图通过文件标题来隐藏字段(Tr),你可以尝试使用$('nobr:contains("field title")'),不管怎样,对于JavaScript/jQuery脚本,总是使用开发人员工具(F12)调试是很有帮助的。
$('nobr:contains("field title")').closest('tr').hide();这里有一个与我在SharePoint 2013中的示例代码类似的线程。
https://stackoverflow.com/questions/54857928
复制相似问题