那么这个函数我们是怎么知道的呢?
你可以在浏览器中查看一个列表的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