gpt4 book ai didi

javascript - 自定义元素的属性可以驼峰式吗?

转载 作者:搜寻专家 更新时间:2023-11-01 05:09:31 24 4
gpt4 key购买 nike

我有一个带有属性的自定义元素:

class MyElement extends HTMLElement {
...
static get observedAttributes() {
return ["camelCaseAttribute"];
}

set camelCaseAttribute(a) {
this._a = a;
}
...
}

我在我的 HTML 中这样使用它:

<my-element camelCaseAttribute="blubb"></my-element>

属性 camelCaseAttribute 在用驼峰式书写时没有设置,但不用大写字母也可以。为什么?

最佳答案

HTML Living Standard, Section 4.13.3 Core Concepts :

4.13.3 Core concepts

Any namespace-less attribute that is relevant to the element's functioning, as determined by the element's author, may be specified on an autonomous custom element, so long as the attribute name is XML-compatible and contains no ASCII upper alphas. The exception is the is attribute, which must not be specified on an autonomous custom element (and which will have no effect if it is).

在 HTML Living Standard 中定义,自定义元素的无命名空间属性必须与 XML 兼容且没有 ASCII 大写字母,因此您的属性不能采用驼峰式命名。

关于javascript - 自定义元素的属性可以驼峰式吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44347580/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com