本文为翻译,英文原版的Cheat Sheet(PDF版本)在此下载:http://aspnetresources.com/downloads/ms_ajax_library_cheat_sheets1.zip
原作版权声明:
Copyright (c) 2004-2006, Milan Negovan http://www.AspNetResources.com All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
注:标注有[S]的为静态方法,无须实例化对象即可使用。
[S] addHandler (element, eventName, handler)
[S] $addHandler (element, eventName, handler)
为DOM元素添加某一事件的处理函数,事件名称应去掉“on”前缀。
注意:在事件处理函数中,this指向的是element,而不一定是发出该事件的元素。
Sys.UI.DomEvent.addHandler (element, "click", clickHandler);
// Same as $addHandler (element, "click", clickHandler);
function clickHandler (e) { … }
[S] addHandlers (element, events, handlerOwner)
[S] $addHandlers (element, events, handlerOwner)
为DOM元素添加多个事件处理函数,events是一个事件处理函数的字典。
注意:在事件处理函数中,若指定了handlerOwner,那么this将指向该handlerOwner,否则将指向element。
$addHandlers ($get ("article"), {
mouseover: onMouseOver,
mouseout: onMouseOut
});
function onMouseOver (e) { this.style.backgroundColor = 'yellow'; }
function onMouseOut (e) { this.style.backgroundColor = 'white'; }
[S] clearHandlers (element)
[S] $clearHandlers (element)
移除指定DOM元素所有的事件处理函数。
Sys.UI.DomEvent.clearHandlers (element);
// Same as $ clearHandlers (element);
[S] removeHandler (element, eventName, handler)
[S] $removeHandler (element, eventName, handler)
为DOM元素移除指定的事件处理函数。
Sys.UI.DomEvent.removeHandler (element, "click", clickHandler);
// Same as $removeHandler (element, "click", clickHandler);
preventDefault ()
阻止执行默认的事件处理函数。例如若阻止了a元素的onclick事件,那么将不会引发页面导航。
$addHandler ($get ("showMoreLink"), "click", showMore);
function showMore (e) { e.preventDefault (); }
stopPropagation ()
阻止事件冒泡传递至父元素。
Event对象的属性