1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
|
---
title: HTMLElement
slug: Web/API/HTMLElement
translation_of: Web/API/HTMLElement
---
<div>{{APIRef}}</div>
<p><span style="line-height: 1.5;">HTMLElement 接口表示所有的 </span><a href="/en-US/docs/Web/HTML" style="line-height: 1.5;" title="/en-US/docs/Web/HTML">HTML</a><span style="line-height: 1.5;"> </span><span style="line-height: 1.5;">元素。一些HTML元素直接实现了HTMLElement接口,其它的间接实现HTMLElement接口.</span></p>
<h2 id="属性">属性</h2>
<p><em>继承自父接口</em><em>{{domxref("Element")}}和</em><em> {{domxref("GlobalEventHandlers")}}</em><em>的属性</em> <em> </em></p>
<table class="standard-table">
<thead>
<tr>
<th scope="col">属性名称</th>
<th scope="col">属性类型</th>
<th scope="col">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{domxref("HTMLElement.accessKey")}}</td>
<td>{{domxref("DOMString")}}</td>
<td>获取/设置元素访问的快捷键</td>
</tr>
<tr>
<td>{{domxref("HTMLElement.accessKeyLabel")}}</td>
<td>{{domxref("DOMString")}}</td>
<td>返回一个包含元素访问的快捷键的字符串(只读)</td>
</tr>
<tr>
<td>{{domxref("HTMLElement.contentEditable")}}</td>
<td>{{domxref("DOMString")}}</td>
<td>获取/设置元素的可编辑状态</td>
</tr>
<tr>
<td>{{domxref("HTMLElement.isContentEditable")}} {{readonlyInline}}</td>
<td>{{domxref("Boolean")}}</td>
<td>表明元素的内容是否可编辑(只读)</td>
</tr>
<tr>
<td>{{domxref("HTMLElement.contextMenu")}}</td>
<td>{{domxref("HTMLMenuElement")}}</td>
<td>设置/获取元素的右键菜单</td>
</tr>
<tr>
<td>{{domxref("HTMLElement.dataset")}} {{readonlyInline}}</td>
<td>{{domxref("DOMStringMap")}}</td>
<td>
<p>获取元素的自定义属性,是一个对象(key-value,只读)</p>
</td>
</tr>
<tr>
<td>{{domxref("HTMLElement.dir")}}</td>
<td>{{domxref("DOMString")}}</td>
<td>
<p><span style="line-height: 1.5;">获取/设置元素的方向,可选的值有:ltr,rtl,auto</span></p>
</td>
</tr>
<tr>
<td>{{domxref("HTMLElement.draggable")}}</td>
<td>{{domxref("Boolean")}}</td>
<td>设置/获取元素是否可以拖拽</td>
</tr>
<tr>
<td>{{domxref("HTMLElement.dropzone")}} {{readonlyInline}}</td>
<td>{{domxref("DOMSettableTokenList")}}</td>
<td> </td>
</tr>
<tr>
<td>{{domxref("HTMLElement.hidden")}}</td>
<td>{{domxref("Boolean")}}</td>
<td>获取/设置元素是否隐藏</td>
</tr>
<tr>
<td>{{domxref("HTMLElement.itemScope")}} {{experimental_inline}}</td>
<td>{{domxref("Boolean")}}</td>
<td> </td>
</tr>
<tr>
<td>{{domxref("HTMLElement.itemType")}} {{readonlyInline}}{{experimental_inline}}</td>
<td>{{domxref("DOMSettableTokenList")}}</td>
<td> </td>
</tr>
<tr>
<td>{{domxref("HTMLElement.itemId")}} {{experimental_inline}}</td>
<td>{{domxref("DOMString")}}</td>
<td> </td>
</tr>
<tr>
<td>{{domxref("HTMLElement.itemRef")}} {{readonlyInline}}{{experimental_inline}}</td>
<td>{{domxref("DOMSettableTokenList")}}</td>
<td> </td>
</tr>
<tr>
<td>{{domxref("HTMLElement.itemProp")}} {{readonlyInline}}{{experimental_inline}}</td>
<td>{{domxref("DOMSettableTokenList")}}</td>
<td> </td>
</tr>
<tr>
<td>{{domxref("HTMLElement.itemValue")}} {{experimental_inline}}</td>
<td>{{domxref("object")}}</td>
<td> </td>
</tr>
<tr>
<td>{{domxref("HTMLElement.lang")}}</td>
<td>{{domxref("DOMString")}}</td>
<td>获取/设置元素属性、文本、内容的语言</td>
</tr>
<tr>
<td>{{domxref("HTMLElement.offsetHeight")}} {{readonlyInline}}</td>
<td><code>double</code></td>
<td>元素自身可视高度加上上下border的宽度</td>
</tr>
<tr>
<td>{{domxref("HTMLElement.offsetLeft")}}{{readonlyInline}}</td>
<td><code>double</code></td>
<td>元素自己border左边距离父元素border左边或者body元素border左边的距离</td>
</tr>
<tr>
<td>{{domxref("HTMLElement.offsetParent")}}{{readonlyInline}}</td>
<td>{{domxref("Element")}}</td>
<td>元素的父元素,如果没有就是body元素</td>
</tr>
<tr>
<td>{{domxref("HTMLElement.offsetTop")}}{{readonlyInline}}</td>
<td><code>double</code></td>
<td>元素自己border顶部距离父元素顶部或者body元素border顶部的距离</td>
</tr>
<tr>
<td>{{domxref("HTMLElement.offsetWidth")}}{{readonlyInline}}</td>
<td><code>double</code></td>
<td>元素自身可视宽度加上左右border的宽度</td>
</tr>
<tr>
<td>{{domxref("HTMLElement.properties")}} {{readonlyInline}}{{experimental_inline}}</td>
<td>{{domxref("HTMLPropertiesCollection")}}</td>
<td> </td>
</tr>
<tr>
<td>{{domxref("HTMLElement.spellcheck")}}{{ gecko_minversion_inline("1.9")}}</td>
<td>{{domxref("Boolean")}}</td>
<td> </td>
</tr>
<tr>
<td>{{domxref("HTMLElement.style")}}</td>
<td>{{domxref("CSSStyleDeclaration")}}</td>
<td>获取/设置元素的style属性</td>
</tr>
<tr>
<td>{{domxref("HTMLElement.tabIndex")}}</td>
<td><code>long</code></td>
<td>获取/设置元素的tab键控制次序</td>
</tr>
<tr>
<td>{{domxref("HTMLElement.title")}}</td>
<td>{{domxref("DOMString")}}</td>
<td>获取/设置元素的title属性</td>
</tr>
<tr>
<td>{{domxref("HTMLElement.translate")}} </td>
<td>{{domxref("Boolean")}}</td>
<td>获取/设置元素是否可以被翻译</td>
</tr>
</tbody>
</table>
<h3 id="Event_handlers">Event handlers</h3>
<p>The events properties, of the form <code>onXYZ</code>, are defined on the {{domxref("GlobalEventHandlers")}}, implemented by <code>HTMLElement</code>. A few more are specific to <code>HTMLElement</code>.</p>
<dl>
<dt>{{domxref("HTMLElement.onTouchStart")}} {{non-standard_inline}}</dt>
<dd>Returns the event handling code for the {{event("touchstart")}} event.</dd>
<dt>{{domxref("HTMLElement.onTouchEnd")}} {{non-standard_inline}}</dt>
<dd>Returns the event handling code for the {{event("touchend")}} event.</dd>
<dt>{{domxref("HTMLElement.onTouchMove")}} {{non-standard_inline}}</dt>
<dd>Returns the event handling code for the {{event("touchmove")}} event.</dd>
<dt>{{domxref("HTMLElement.onTouchEnter")}} {{non-standard_inline}}</dt>
<dd>Returns the event handling code for the {{event("touchenter")}} event.</dd>
<dt>{{domxref("HTMLElement.onTouchLeave")}} {{non-standard_inline}}</dt>
<dd>Returns the event handling code for the {{event("touchleave")}} event.</dd>
<dt>{{domxref("HTMLElement.onTouchCancel")}} {{non-standard_inline}}</dt>
<dd>Returns the event handling code for the {{event("touchcancel")}} event.</dd>
</dl>
<h2 id="方法">方法</h2>
<p><em>从父元素继承的方法, {{domxref("Element")}}.</em></p>
<table class="standard-table">
<thead>
<tr>
<th scope="col">Name & Arguments</th>
<th scope="col">Return</th>
<th scope="col">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{domxref("HTMLElement.blur()")}}</td>
<td><code>void</code></td>
<td>元素失去焦点</td>
</tr>
<tr>
<td>{{domxref("HTMLElement.click()")}}</td>
<td><code>void</code></td>
<td>触发元素的点击事件</td>
</tr>
<tr>
<td>{{domxref("HTMLElement.focus()")}}</td>
<td><code>void</code></td>
<td>元素获得焦点</td>
</tr>
<tr>
<td>{{domxref("HTMLElement.forceSpellCheck()")}} {{experimental_inline}}</td>
<td><code>void</code></td>
<td> </td>
</tr>
</tbody>
</table>
<h2 id="规范">规范</h2>
<table class="standard-table">
<thead>
<tr>
<th scope="col">Specification</th>
<th scope="col">Status</th>
<th scope="col">Comment</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{SpecName('CSSOM View', '#extensions-to-the-htmlelement-interface', 'HTMLElement')}}</td>
<td>{{Spec2('CSSOM View')}}</td>
<td>
<p>添加如下属性:</p>
<p><code>offsetParent<font face="Open Sans, arial, sans-serif">,</font></code><code>offsetTop<font face="Open Sans, arial, sans-serif">,</font></code><code>offsetLeft<font face="Open Sans, arial, sans-serif">,</font></code><code>offsetWidth<font face="Open Sans, arial, sans-serif">,</font></code><code>offsetHeight</code></p>
</td>
</tr>
<tr>
<td>{{SpecName('HTML WHATWG', 'elements.html#htmlelement', 'HTMLElement')}}</td>
<td>{{Spec2('HTML WHATWG')}}</td>
<td>
<p>添加如下属性:</p>
<p><code>translate<font face="Open Sans, arial, sans-serif">,</font></code><code>itemScope<font face="Open Sans, arial, sans-serif">,</font></code><code>itemType<font face="Open Sans, arial, sans-serif">,</font></code><code>itemId<font face="Open Sans, arial, sans-serif">,</font></code><code>itemRef<font face="Open Sans, arial, sans-serif">,</font></code><code>itemProp<font face="Open Sans, arial, sans-serif">,</font></code><code>properties,</code><code>itemValue。</code></p>
<p><code>添加如下方法:</code><br>
<code>forceSpellcheck(),</code></p>
<p><code>将 onXYZ 属性移动到了</code>{{domxref("GlobalEventHandlers")}}接口上并从该接口继承了该属性</p>
</td>
</tr>
<tr>
<td>{{SpecName('HTML5 W3C', 'dom.html#htmlelement', 'HTMLElement')}}</td>
<td>{{Spec2('HTML5 W3C')}}</td>
<td>
<p>添加了如下属性:</p>
<p><code>dataset</code>, <code>hidden</code>, <code>tabindex</code>, <code>accessKey</code>, <code>accessKeyLabel</code>, <code>draggable</code>, <code>dropzone</code>, <code>contentEditable</code>, <code>isContentEditable</code>, <code>contextMenu</code>, <code>spellcheck</code>, <code>commandType</code>, <code>commandLabel</code>, <code>commandIcon</code>, <code>commandHidden</code>, <code>commandDisabled</code>, <code>commandChecked</code>, <code>style,和所有的 onXYZ属性</code></p>
<p><code>移动id和classname属性到</code>{{domxref("Element")}}接口上</p>
</td>
</tr>
<tr>
<td>{{SpecName('DOM2 HTML', 'html.html#ID-011100101', 'HTMLElement')}}</td>
<td>{{Spec2('DOM2 HTML')}}</td>
<td>在 {{SpecName('DOM2 HTML')}}基础上没有任何改变</td>
</tr>
<tr>
<td>{{SpecName('DOM1', 'level-one-html.html#ID-011100101', 'HTMLElement')}}</td>
<td>{{Spec2('DOM1')}}</td>
<td>初始定义</td>
</tr>
</tbody>
</table>
<h2 id="浏览器兼容性">浏览器兼容性</h2>
<p>{{CompatibilityTable}}</p>
<div id="compat-desktop">
<table class="compat-table">
<tbody>
<tr>
<th>特性</th>
<th>Firefox (Gecko)</th>
<th>Chrome</th>
<th>Internet Explorer</th>
<th>Opera</th>
<th>Safari</th>
</tr>
<tr>
<td>Basic support</td>
<td>{{CompatGeckoDesktop("1.0")}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatUnknown}}</td>
</tr>
<tr>
<td>{{domxref("HTMLElement.accessKey", "accessKey")}}</td>
<td>{{CompatGeckoDesktop("5.0")}}</td>
<td>17.0</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatVersionUnknown}}(<a class="external" href="http://trac.webkit.org/changeset/107483">535.10</a>)</td>
</tr>
<tr>
<td>{{domxref("HTMLElement.accessKeyLabel", "accessKeyLabel")}}</td>
<td>{{CompatGeckoDesktop("8.0")}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatNo}}{{WebkitBug(72715)}}</td>
</tr>
<tr>
<td>{{domxref("HTMLElement.blur()", "blur()")}}</td>
<td>{{CompatGeckoDesktop("5.0")}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatUnknown}}</td>
</tr>
<tr>
<td>{{domxref("HTMLElement.click()", "click()")}}</td>
<td>{{CompatGeckoDesktop("5.0")}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatVersionUnknown}}(<a class="external" href="http://trac.webkit.org/changeset/107483">535.24</a>)</td>
</tr>
<tr>
<td>{{domxref("HTMLElement.dataset", "dataset")}}</td>
<td>{{CompatGeckoDesktop("6.0")}}</td>
<td>9.0</td>
<td>{{CompatUnknown}}</td>
<td>11.10</td>
<td>5.1</td>
</tr>
<tr>
<td>{{domxref("HTMLElement.focus()", "focus()")}}</td>
<td>{{CompatGeckoDesktop("5.0")}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatUnknown}}</td>
</tr>
<tr>
<td>{{domxref("HTMLElement.contentEditable", "contentEditable")}}</td>
<td>{{CompatGeckoDesktop("1.9")}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>5.5</td>
<td>9</td>
<td>{{CompatVersionUnknown}}</td>
</tr>
<tr>
<td>{{domxref("HTMLElement.spellcheck", "spellcheck")}}</td>
<td>{{CompatGeckoDesktop("1.8.1")}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatUnknown}}</td>
</tr>
<tr>
<td>{{domxref("HTMLElement.forceSpellCheck", "forceSpellCheck()")}} {{experimental_inline}}</td>
<td>{{CompatNo}}</td>
<td>{{CompatNo}}</td>
<td>{{CompatNo}}</td>
<td>{{CompatNo}}</td>
<td>{{CompatNo}}</td>
</tr>
<tr>
<td>{{domxref("HTMLElement.dataset", "dataset")}}</td>
<td>{{CompatGeckoDesktop("6.0")}}</td>
<td>8.0</td>
<td>11</td>
<td>11.10</td>
<td>6</td>
</tr>
<tr>
<td>{{domxref("HTMLElement.draggable", "draggable")}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatUnknown}}</td>
<td>12.0</td>
<td>{{CompatUnknown}}</td>
</tr>
<tr>
<td>{{domxref("HTMLElement.dropzone", "dropzone")}}</td>
<td>{{CompatNo}}</td>
<td>{{CompatNo}}</td>
<td>{{CompatNo}}</td>
<td>12.0</td>
<td>{{CompatNo}}</td>
</tr>
<tr>
<td>{{domxref("HTMLElement.offsetLeft", "offsetLeft")}}, {{domxref("HTMLElement.offsetTop", "offsetTop")}}, {{domxref("HTMLElement.offsetParent", "offsetParent")}}, {{domxref("HTMLElement.offsetHeight", "offsetHeight")}} and {{domxref("HTMLElement.offsetWidth", "offsetWidth")}} {{experimental_inline}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatUnknown}}</td>
</tr>
<tr>
<td>{{domxref("HTMLElement.translate", "translate")}} {{experimental_inline}}</td>
<td>{{CompatNo}}</td>
<td>{{CompatNo}}</td>
<td>{{CompatNo}}</td>
<td>{{CompatNo}}</td>
<td>{{CompatNo}}</td>
</tr>
<tr>
<td>{{domxref("HTMLElement.itemScope", "itemScope")}}, {{domxref("HTMLElement.itemType", "itemType")}}, {{domxref("HTMLElement.itemRef", "itemRef")}}, {{domxref("HTMLElement.itemId", "itemId")}}, {{domxref("HTMLElement.itemProp", "itemProp")}}, and {{domxref("HTMLElement.itemValue", "itemValue")}} {{experimental_inline}}</td>
<td>{{CompatGeckoDesktop("6.0")}}</td>
<td>{{CompatNo}}</td>
<td>{{CompatNo}}</td>
<td>11.60<br>
(Removed in Opera 15)</td>
<td>{{CompatNo}}</td>
</tr>
<tr>
<td>{{domxref("HTMLElement.properties", "properties")}} {{experimental_inline}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatUnknown}}</td>
</tr>
<tr>
<td>{{domxref("HTMLElement.ontouchstart")}}, {{domxref("HTMLElement.ontouchend")}}, {{domxref("HTMLElement.ontouchmove")}}, {{domxref("HTMLElement.ontouchenter")}}, {{domxref("HTMLElement.ontouchleave")}}, and {{domxref("HTMLElement.ontouchcancel")}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatNo}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatVersionUnknown}}</td>
</tr>
</tbody>
</table>
</div>
<div id="compat-mobile">
<table class="compat-table">
<tbody>
<tr>
<th>Feature</th>
<th>Firefox Mobile (Gecko)</th>
<th>Android</th>
<th>IE Mobile</th>
<th>Opera Mobile</th>
<th>Safari Mobile</th>
</tr>
<tr>
<td>Basic support</td>
<td>
<p>{{CompatGeckoMobile("1.0")}}</p>
</td>
<td rowspan="7">{{CompatUnknown}}</td>
<td rowspan="7">{{CompatUnknown}}</td>
<td rowspan="7">{{CompatUnknown}}</td>
<td rowspan="7">{{CompatUnknown}}</td>
</tr>
<tr>
<td>{{domxref("HTMLElement.accessKey", "accessKey")}}</td>
<td>{{CompatGeckoMobile("5.0")}}</td>
</tr>
<tr>
<td>{{domxref("HTMLElement.accessKeyLabel", "accessKeyLabel")}}</td>
<td>{{CompatGeckoMobile("8.0")}}</td>
</tr>
<tr>
<td>{{domxref("HTMLElement.blur()", "blur()")}}</td>
<td>{{CompatGeckoMobile("5.0")}}</td>
</tr>
<tr>
<td>{{domxref("HTMLElement.click()", "click()")}}</td>
<td>{{CompatGeckoMobile("5.0")}}</td>
</tr>
<tr>
<td>{{domxref("HTMLElement.dataset", "dataset")}}</td>
<td>{{CompatGeckoMobile("6.0")}}</td>
</tr>
<tr>
<td>{{domxref("HTMLElement.focus()", "focus()")}}</td>
<td>{{CompatGeckoMobile("5.0")}}</td>
</tr>
</tbody>
</table>
</div>
<h2 id="sect1"> </h2>
<h2 id="还可以查看以下内容:">还可以查看以下内容:</h2>
<ul>
<li>{{domxref("Element")}}</li>
</ul>
|