Join MDN and developers like you at Mozilla's View Source conference, 12-14 September in Berlin, Germany. Learn more at https://viewsourceconf.org

HTMLElement

这篇翻译不完整。请帮忙从英语翻译这篇文章

HTMLElement 接口表示所有的 HTML 元素。一些HTML元素直接实现了HTMLElement接口,其它的间接实现HTMLElement接口.

属性

继承自父接口Element GlobalEventHandlers的属性  

属性名称 属性类型 Description
HTMLElement.accessKey DOMString 分配给元素的access key
HTMLElement.accessKeyLabel DOMString A string that represents the element's assigned access key.
HTMLElement.contentEditable DOMString 获取/设置元素的可编辑状态
HTMLElement.isContentEditable 只读 Boolean 指示元素的内容是否可被编辑
HTMLElement.dataset 只读 DOMStringMap

允许读写元素的自定义data特性(data-*)

HTMLElement.dir DOMString

获取/设置元素的方向

HTMLElement.draggable Boolean  
HTMLElement.dropzone 只读 DOMSettableTokenList  
HTMLElement.hidden Boolean  
HTMLElement.itemScope Boolean  
HTMLElement.itemType 只读 DOMSettableTokenList  
HTMLElement.itemId DOMString  
HTMLElement.itemRef 只读 DOMSettableTokenList  
HTMLElement.itemProp 只读 DOMSettableTokenList  
HTMLElement.itemValue any  
HTMLElement.lang DOMString 获取/设置元素属性、文本、内容的语言(Gets/sets the language of an element's attributes, text, and element contents).
HTMLElement.offsetHeight 只读 double The height of an element, relative to the layout.
HTMLElement.offsetLeft只读 double The distance from this element's left border to its offsetParent's left border.
HTMLElement.offsetParent只读 Element The element from which all offset calculations are currently computed.
HTMLElement.offsetTop只读 double The distance from this element's top border to its offsetParent's top border.
HTMLElement.offsetWidth只读 double The width of an element, relative to the layout.
HTMLElement.properties 只读 HTMLPropertiesCollection  
HTMLElement.spellcheck Boolean Controls spell-checking (present on all HTML elements)
HTMLElement.style CSSStyleDeclaration An object representing the declarations of an element's style attributes.
HTMLElement.tabIndex long Gets/sets the position of the element in the tabbing order.
HTMLElement.title DOMString A string that appears in a popup box when mouse is over the element.
HTMLElement.translate Boolean  

Event handlers

The events properties, of the form onXYZ, are defined on the GlobalEventHandlers, implemented by HTMLElement. A few more are specific to HTMLElement.

HTMLElement.onTouchStart
Returns the event handling code for the touchstart event.
HTMLElement.onTouchEnd
Returns the event handling code for the touchend event.
HTMLElement.onTouchMove
Returns the event handling code for the touchmove event.
HTMLElement.onTouchEnter
Returns the event handling code for the touchenter event.
HTMLElement.onTouchLeave
Returns the event handling code for the touchleave event.
HTMLElement.onTouchCancel
Returns the event handling code for the touchcancel event.

方法

从父元素继承的方法, Element.

Name & Arguments Return Description
HTMLElement.blur() void 从当前已经获得焦点的元素上移除键盘焦点(Removes keyboard focus from the currently focused element).
HTMLElement.click() void 在该元素上触发click事件(Sends a mouse click event to the element).
HTMLElement.focus() void 让当前元素获取焦点(Makes the element the current keyboard focus).
HTMLElement.forceSpellCheck() void  

规范

Specification Status Comment
CSS Object Model (CSSOM) View Module
HTMLElement
Working Draft

添加了如下属性:

offsetParent, offsetTop, offsetLeft, offsetWidth, and offsetHeight.

WHATWG HTML Living Standard
HTMLElement
Living Standard

添加了如下属性:

translate, itemScope, itemType, itemId, itemRef, itemProp, properties, and itemValue.
Added the following method: forceSpellcheck().
Moved the onXYZ attributes to the GlobalEventHandlers interface and added an inheritance from it.

HTML5
HTMLElement
Recommendation

添加了如下属性:

dataset, hidden, tabindex, accessKey, accessKeyLabel, draggable, dropzone, contentEditable, isContentEditable, contextMenu, spellcheck, commandType, commandLabel, commandIcon, commandHidden, commandDisabled, commandChecked, style, and all the onXYZ properties.
Moved the id and className properties to the Element interface.

Document Object Model (DOM) Level 2 HTML Specification
HTMLElement
Recommendation No change from Document Object Model (DOM) Level 2 HTML Specification
Document Object Model (DOM) Level 1 Specification
HTMLElement
Recommendation 初始定义.

浏览器兼容性

特性 Firefox (Gecko) Chrome Internet Explorer Opera Safari
Basic support 1.0 (1.7 or earlier) ? ? ? ?
accessKey 5.0 (5.0) 17.0 ? ? (Yes)(535.10)
accessKeyLabel 8.0 (8.0) ? ? ? 未实现WebKit bug 72715
blur() 5.0 (5.0) ? ? ? ?
click() 5.0 (5.0) ? ? ? (Yes)(535.24)
dataset 6.0 (6.0) 9.0 ? 11.10 5.1
focus() 5.0 (5.0) ? ? ? ?
contentEditable 3.0 (1.9) (Yes) 5.5 9 (Yes)
spellcheck 2.0 (1.8.1) ? ? ? ?
forceSpellCheck() 未实现 未实现 未实现 未实现 未实现
dataset 6.0 (6.0) 8.0 11 11.10 6
draggable (Yes) ? ? 12.0 ?
dropzone 未实现 未实现 未实现 12.0 未实现
offsetLeft, offsetTop, offsetParent, offsetHeight and offsetWidth (Yes) ? (Yes) ? ?
translate 未实现 未实现 未实现 未实现 未实现
itemScope, itemType, itemRef, itemId, itemProp, and itemValue 6.0 (6.0) 未实现 未实现 11.60
(Removed in Opera 15)
未实现
properties (Yes) ? ? ? ?
HTMLElement.ontouchstart, HTMLElement.ontouchend, HTMLElement.ontouchmove, HTMLElement.ontouchenter, HTMLElement.ontouchleave, and HTMLElement.ontouchcancel (Yes) (Yes) 未实现 ? (Yes)
Feature Firefox Mobile (Gecko) Android IE Mobile Opera Mobile Safari Mobile
Basic support

1.0 (1.0)

? ? ? ?
accessKey 5.0 (5.0)
accessKeyLabel 8.0 (8.0)
blur() 5.0 (5.0)
click() 5.0 (5.0)
dataset 6.0 (6.0)
focus() 5.0 (5.0)

 

还可以查看以下内容:

文档标签和贡献者

 此页面的贡献者: chengxc, zccst, fscholz, a06062125
 最后编辑者: chengxc,