Mozilla.com

  1. MDC
  2. 首页
  3. DOM
  4. element.id

« Gecko DOM 参考

摘要

获取/设置元素的标识符.

语法

idStr = element.id
element.id = idStr

这里idStr 是这个元素的 ID.

注意

ID 在文档中必须是唯一的, 它常常用来通过document.getElementById方法查找元素.

In some documents (in particular, HTML, XUL, and SVG), the id of an element can be specified as an attribute on the element like so: <div id="table-cell2">.

However you can't use this attribute in a custom XML document without correctly specifying the type of the id attribute in the DOCTYPE. See getElementById Pitfalls for details.

Other common usages of id include using the element's ID as a selector when styling the document with CSS.

Page last modified 18:05, 2 Dec 2006 by Mgjbot

文件 (0)