2015-06-30 67 views

回答

0

轉到您的列表主網頁,然後

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

然後點擊Add a Web PartCategories下選擇Media and Content > 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//[library internal name]/。然後附加scrpt名稱。你可以注意到,相對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

+0

我能在內容鏈接添加URL。 我需要在標題或正文部分添加web部件嗎? 我該如何編輯newform.aspx? – saeid10

+0

@ saeid10當您點擊'默認新窗體'時,您可以在框中看到'添加Web部件'。點擊它。 – Dien

+0

謝謝我完成了。 但我使用了網站上的html代碼 – saeid10

1

步驟:

  • 下載SPUtility.js
  • 將下載的文件(SPUtility.js)上載到SharePoint網站中的適當位置,如「樣式庫」。
  • 打開您的列表>從上面的功能區,>在'自定義列表'部分>點擊'表單Web部件'>選擇'默認新窗體'。
  • 在新窗體中添加腳本編輯器。
  • 編輯代碼片段>添加以下代碼。

代碼

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> 
<script src="/Style%20Library/sputility.js"></script> 
<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> 

[OUTPUT]

enter image description here

enter image description here

注意:Job Title替換爲您選擇的字段名稱,並將Other Title替換爲您需要顯示或隱藏的字段,並根據 選擇字段選擇。

對於編輯/顯示形式和更多的細節檢查Show/Hide fields based on a drop down field using SPUtility.js

替代方法檢查Show/Hide fields based on choice field selection using JQuery in SharePoint

相關問題