_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