当前位置: 首页 > 网络学院 > 客户端脚本教程 > HTML DOM > HTML DOM getElementById() 方法

HTML DOM
DOM TableRow 对象
DOM Textarea 对象
DOM Window 对象

HTML DOM getElementById() 方法


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-04   浏览: 500 ::
收藏到网摘: n/a

Definition and Usage
定义与用法

The getElementById() method returns a reference to the first object with the specified ID.
getElementById()方法可返回带有指定ID的第一个对象的参考

Syntax
语法

document.getElementById(id)


Example
举例

<html>
<head>
<script type="text/javascript">
function getElement()
{
var x=document.getElementById("myHeader")
alert("I am a " + x.tagName + " element")
}
</script>
</head>
<body>
<h1 id="myHeader" onclick="getElement()">
Click to see what element I am!</h1>
</body>
</html>


Try-It-Yourself Demos

Use getElementById()
使用getElementById()

Form validation
表单校验

Set focus to an input field when the page loads
当页面加载的时候input获得聚焦

Select the content of an input field
选择input里的内容

Radiobuttons in a form
表单里的单选按钮

Checkboxes in a form
表单里的复选框

Dropdown list in a form
在表单里的下拉菜单

Another dropdown list
另一种下拉菜单

A dropdown menu
下拉菜单

Jump to the next field when the current field's maxlength has been reached
当前的input输入到最到范围后自动跳到下一个input

评论 (0) All

登陆 | 还没注册?