document.createElement multiple arguments

故事扮演 提交于 2019-12-11 02:59:15

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!