2017-06-01 126 views
0

我在使用Sharepoint中的jQuery添加可摺疊標題時遇到問題。我使用Sharepoint中的腳本編輯器Web部件導入jQuery,但是當我使用多個標記時,這會導致問題。在Sharepoint中添加可摺疊標題(jQuery)

我的代碼是:

<script type="text/javascript" src="https://code.jquery.com/jquery-1.11.3.min.js"></script> 
<script type="text/javascript" src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script> 

我周圍我的頭用是

<div data-role="collapsible"> 
    <h1>Header</h1> 
    <p>Content</p> 
</div> 

當我在腳本編輯器中添加腳本標籤jQuery的代碼,我的網頁編輯按鈕不再作品。我需要刪除頁面中的腳本部分,以便它再次運行。 我如何在Sharepoint中實現這一點?謝謝。

回答

0

您提供的代碼應該可以工作,但是如果您想嘗試其他方法,則可以運行此代碼。這將增加scriptlink到網頁在您的網頁位於(jQuery將在所有網頁出現在這個特定的web)

JavaScript代碼:

var clientContext = SP.ClientContext.get_current() 
var web = clientContext.get_web(); 
var UserCustomActions = web.get_userCustomActions(); 
clientContext.load(UserCustomActions) 

var action = UserCustomActions.add(); 
action.set_location('ScriptLink'); 
action.set_sequence(5); 
action.set_title('jQuery'); 
action.set_description('jQuery'); 
action.set_scriptBlock("document.write(\"<script type='text/javascript' src='https://code.jquery.com/jquery-1.11.3.min.js'><\\/script>\");"); 
action.update(); 

clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed)); 

function onQuerySucceeded(sender, args) { 
    alert("done"); 
} 

function onQueryFailed(sender, args) { 
    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace()); 
}