我试图创建一个名为test的新HTML元素: <test>some text</test>
我试图像这样对它进行原型设计:HTMLUnknownElement.prototype.style.backgroundColor = "red";但它不起作用.
你能帮帮我,怎么管理它?
提前致谢,
怎么样createElement()?
var el = document.createElement("test");
el.style.backgroundColor = "red";
document.body.appendChild(el);
Run Code Online (Sandbox Code Playgroud)
如果我们开始:
<html>
<head></head>
<body>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
结果将是:
<html>
<head></head>
<body>
<test style="background-color:red"></test>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)