【问题标题】:Hide field based on drop down selection in sharepoint new item基于共享点新项目中的下拉选择隐藏字段
【发布时间】:2020-05-06 05:43:42
【问题描述】:

我是 sharepoint 的新手。

我已经创建了一个列表。在新项目窗口中,我想根据下拉选择值显示或隐藏字段。我知道它可以使用 jquery 来完成,如下面的链接所示。但我不知道在哪里放置代码。

https://sharepoint.stackexchange.com/questions/88064/hide-show-field-on-list-form-based-on-value-from-another-field

谢谢

【问题讨论】:

    标签: javascript sharepoint-2010 show-hide


    【解决方案1】:

    步骤:

    • 下载SPUtility.js
    • 将下载的文件 (SPUtility.js) 上传到 SharePoint 站点中的适当位置,例如“样式库”。
    • 打开您的列表 > 从上面的功能区中,> 在“自定义列表”部分 > 单击“表单 Web 部件”> 选择“默认新表单”。
    • 在您的新表单中添加脚本编辑器。
    • 编辑片段 > 添加以下代码。

    代码

    <script>
     $(document).ready(function () 
    { // Get a the choice field 
    var choiceField = SPUtility.GetSPField('Job Title');
    // Hide the target fields in form load
    SPUtility.GetSPField('Other Title').Hide();
    // create a function to show or hide a field based on the selected choice Field value 
    var ShowHideField = function() { 
    var selectedFieldValue = choiceField.GetValue(); 
    // Hide the 'Other Title' field if the selected value is 'Other' 
    if(selectedFieldValue != 'Other') { 
    SPUtility.GetSPField('Other Title').Hide(); } 
    else { SPUtility.GetSPField('Other Title').Show(); } }; 
    // attach the function to choice field 
    $(choiceField.Dropdown).on('change', ShowHideField); });
    </script>
    

    [输出]

    注意:Job Title 替换为您选择的字段名称,将Other Title 替换为您需要显示或隐藏的字段 选择字段选择。

    更多详情,请查看

    【讨论】:

      【解决方案2】:

      然后转到您的列表主页

      List Tools>List>Form Web Parts>Default New Form
      

      然后单击Add a Web Part 并在Categories 下选择Media and Content &gt; Content Editor。点击Add将其添加到页面。
      在内容编辑器的左侧,您将看到一个箭头。单击它并选择Edit Web Part。在Content Link 下单击按钮打开Text Editor。添加您的 aspx 页面的 URL。
      例如,如果页面存储在Site Assets 库中并称为newform.aspx,则url 为[url path to site assets]/SiteAssets/newform.aspx。转到存储脚本的位置并复制浏览器显示的链接:复制到/SiteAssets/ 或@ 987654333@ 另一个图书馆。然后附加脚本名称。您会注意到相对 URL 就足够了,它从 /sites/ 开始。
      但是 newform.aspx 必须这样编辑:

              <asp:Content ContentPlaceHolderId="PlaceHolderAdditionalPageHead" runat="server">
                  <SharePoint:ScriptLink Name="sp.ribbon.js" runat="server" OnDemand="true" Localizable="false" />
                  <SharePoint:ScriptLink Name="SP.js" runat="server" OnDemand="true" Localizable="false" />
      
                  <script type="text/javascript">
                      /*Your script here*/
                      /*examples*/
                      myFunction1()
                      {}
                      myFunction2()
                      {}
                       jQuery(document).ready(function ($) 
                       {                           
                              ExecuteOrDelayUntilScriptLoaded(myFunction1, "sp.js");          //if the function operates on the form
                              ExecuteOrDelayUntilScriptLoaded(myFunction2, "sp.ribbon.js");   //if the function operates on the ribbon
                      });
      
                  </script> 
      
                  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                   <html xmlns="http://www.w3.org/1999/xhtml">
                          <head>
                              <meta content="text/html; charset=windows-1252" http-equiv="Content-Type" />
                              <title>Page</title>
                          </head>
                          <body>
      
                          </body>
      
                  </html>
      
          </asp:Content>
      

      1。如果您想处理表单和/或功能区,请通过在页面顶部添加必要的标签来请求服务器加载 sp.js and sp.ribbon.js
      2.您可以添加自定义html:否则删除
      3.另存为.aspx

      【讨论】:

      • 我能够在内容链接下添加 URL。我需要在页眉或正文部分添加 Web 部件吗?如何编辑 newform.aspx?
      • @saeid10 当您单击Default New Form 时,您可以在一个框内看到Add a Web Part。点击它。
      • 谢谢我搞定了。但我使用了网站上的 html 代码
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-16
      • 2021-06-15
      • 1970-01-01
      • 2014-02-27
      相关资源
      最近更新 更多