SharePoint提供的一些javascript函數

來源:互聯網
上載者:User

_spBodyOnLoadFunctionNames

=============

這是一個數組, Javascript程式員可以使用SharePoint Designer編輯SharePoint頁面, 把自己定義的函數名push到這個數組中, 然後這個javascirpt函數會在頁面初始化的時候被調用.

_spBodyOnLoadFunctionNames.push("MyInitFunction");

 

PreSaveItem

=============

如果你要在建立一個list item之前, 進行一些驗證工作, 那麼你需要實現一個PreSaveItem函數.

 

那麼這個函數我們是怎麼知道的呢?

你可以在瀏覽器中查看一個列表的NewForm.aspx頁面的原始碼, 你會發現"Finish"這個按鈕的onclick事件裡有這個函數的調用.

<input type="button" 
name="ctl00$m$g_blah_blah_blah_$diidIOSaveItem"
value="Finish"
onclick="if (!PreSaveItem())return false;
WebForm_DoPostBackWithOptions(
new WebForm_PostBackOptions(......))"
id="ctl00_m_g_blah_blah_blah_diidIOSaveItem"
accesskey="S"
class="ms-ButtonHeightWidth"
target="_self"
/>

 

這個PreSaveItem函數是定義在C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\LAYOUTS\1033\form.js檔案中的.

//Code below is from form.js of SharePoint OOB js file
function PreSaveItem()
{
if ("function"==typeof(PreSaveAction))
{
return PreSaveAction();
}
return true;
}

 

如何使用呢? 很簡單.

//Code below is from your aspx file.
function PreSaveItem() {
// Do your thing here
// .......
}

 

OptLoseFocus(opt)

=============

該函數來自core.js, 定義如下:

function OptLoseFocus(opt)
{
var ctrl=document.getElementById(opt.ctrl);
if (opt.selectedIndex >=0)
SetCtrlFromOpt(ctrl, opt);
opt.style.display="none";
}

 

作用是設定某個控制項的選項為被選中的狀態.

 

ShowDropdown(textboxID)

=============

顯示dorpdown控制項, 定義在core.js和ows.js, 定義如下:

function ShowDropdown(textboxId)
{
var ctrl=document.getElementById(textboxId);
var str=ctrl.value;
var opt=EnsureSelectElement(ctrl, ctrl.opt);
ctrl.match=FilterChoice(opt, ctrl, "", ctrl.value);
ctrl.focus();
}

 

 

資料來源:

SharePoint JavaScript – Page Load Add function: _spBodyOnLoadFunctionNames

http://blogs.msdn.com/b/saurabhkv/archive/2009/06/22/javascript-pageload-add-function.aspx

Add JavaScript Date Validation into List Item forms

http://edinkapic.blogspot.com/2007/10/add-javascript-date-validation-into.html

Using Javascript to Manipulate a List Form Field

http://blogs.msdn.com/b/sharepoint/archive/2007/06/21/using-javascript-to-manipulate-a-list-form-field.aspx

 

=============other javascript resources================

http://sharepointdevwiki.com/display/public/SharePoint+JavaScript+Functions+Overview

http://hilfiger1014.spaces.live.com/Blog/cns!B5605D7C2A738C3D!1140.entry

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.