更新:2007 年 11 月
获取一个 DOM 元素,该元素具有指定的 id 属性。此成员是静态的,可在不创建类实例的情况下调用。
Sys.UI.DomElement.getElementById(id, element);
参数
项 |
定义 |
|---|---|
id |
要查找的元素的 ID。 |
element |
要在其中进行搜索的父元素。默认值为 document 元素。 |
返回值
具有指定 ID 的 Sys.UI.DomElement 对象。
备注
$get 方法提供访问 Sys.UI.DomElement 类的 getElementById 方法的快捷方式。
示例
下面的示例演示如何使用 getElementById 方法。此代码摘自 DomElement 类概述中一个更大的示例。
// Add handler using the getElementById method
$addHandler(Sys.UI.DomElement.getElementById("Button1"), "click", toggleCssClassMethod);
// Add handler using the shortcut to the getElementById method
$addHandler($get("Button2"), "click", removeCssClassMethod);
// Add handler using the getElementById method
$addHandler(Sys.UI.DomElement.getElementById("Button1"), "click", toggleCssClassMethod);
// Add handler using the shortcut to the getElementById method
$addHandler($get("Button2"), "click", removeCssClassMethod);