内容编辑器Web部件(CEWP)中的JavaScript

时间:2019-02-21 22:46:37

标签: javascript sharepoint editor cewp

在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>

0 个答案:

没有答案