我试图定义一个新的自定义元素扩展 HTMLFormElement 像:
class PrintableFormElement extends HTMLFormElement {
constructor() {
super();
console.log("created: ", this);
}
print() { console.log(this.elements)); }
}
customElements.define("printable-form", PrintableFormElement, { extends: "form" });
这行不通。 <form is="printable-form" ...>
没有 print()
方法(define(...)
似乎失败了)和new PrintableFormElement
因 Google Chrome 55 错误而失败。
new PrintableFormElement
抛出以下错误:
Uncaught TypeError: Illegal constructor
at PrintableFormElement (<anonymous>:3:5)
at <anonymous>:1:1
我不知道如何在当前的 Google Chrome 中使用自定义元素 v1 定义自定义元素扩展。
Custom Elements v0 效果很好,但我想使用它。
最佳答案
自定义内置元素“v1”尚未在 Chrome 中实现,您应该使用 一个 polyfill。
有关更多详细信息,另请参阅来自 SO 的这个问题:
关于javascript - 如何在 Google Chrome 中使用自定义元素 v1 扩展 <form>?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41457420/