我注意到我可以使用 a
来引用 ID 为“a”的元素,但我不确定这个“方法”是否有名称。
例如,这会将 div 的文本设置为“b c”。
<div id="a" class="b c"></div>
<script>a.innerHTML = a.classList</script>
最佳答案
好像叫Named access on the Window object通过 HTML5 标准。了解更多 here
The window object must have a property
key
whose value iselem
if:
there is exactly one DOM element
elem
whose propertyid
has the valuekey
.there is exactly one DOM element
elem
whose propertyname
has the valuekey
.elem
’s tag must be one of: a, applet, area, embed, form, frame, frameset, iframe, img, object.
关于javascript - 当我可以使用 JS 中的 ID 选择 HTML 元素时,它被称为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40174390/