【发布时间】:2021-06-23 14:12:11
【问题描述】:
我正在努力让我的项目对我自己来说是可读的,并且我正在尝试创建新的自定义 HTML 元素。
document.createElement("name", {is: "h2"});
document.createElement("avatar", {is: "img"});
document.createElement("description", {is: "p"});
这就是我使用它们的方式
$(`<avatar class="dropshadow" src="${friend.avatar}">`).appendTo(box);
$(`<name class="name">${friend.name}</name>`).appendTo(box);
$(`<description class="noselect">${friend.description}</description>`).appendTo(box);
很遗憾,这些都不起作用。它们不被视为继承的元素。
检查节点时,原型是HTMLUnknownElementPrototype,这告诉我它不起作用。
我在这里做错了什么?这没有意义。
【问题讨论】:
-
我不认为这是他们的工作方式。查看documentation!
-
我已经多次查看文档,但我尝试的一切都不起作用。我无法用它创建自己的元素。
标签: javascript html createelement