问题
I was reading through the polymer documentation, and I saw this:
var el2 = document.createElement('input', 'my-input');
Source
Forgetting about polymer for a second, can document.createElement
currently take 2 arguments? Is it related to Polymer's type-extensions?
Side note: Webstorm was "complaining" when I called it with 2 arguments.
回答1:
At the moment, document.createElement
will only take one parameter (Ignoring the second). It does appear that there is a spec that will allow you to pass a typeExtension
which you can read about here. This spec is still in the works, and is not implemented in any form on any browser as of yet.
Quick edit: It does appear that chrome stable does contain the typeExtension
parameter, which can be found here. Thanks @ScottMiles for the clarification.
回答2:
No it can not. FROM MDN: In an HTML document, the Document.createElement() method creates the specified HTML element or an HTMLUnknownElement if the given element name isn't a known one.
var element = document.createElement(tagName);
element is the created Element object. tagName is a string that specifies the type of element to be created. The nodeName of the created element is initialized with the value of tagName.
https://developer.mozilla.org/en-US/docs/Web/API/Document/createElement
来源:https://stackoverflow.com/questions/30767350/document-createelement-multiple-arguments