SharePoint提供的一些javascript函数

_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

posted on   中道学友  阅读(1403)  评论(1编辑  收藏  举报

编辑推荐:
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律

导航

< 2010年5月 >
25 26 27 28 29 30 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

技术追求准确,态度积极向上

点击右上角即可分享
微信分享提示