document.createElement 多个参数
document.createElement multiple arguments
我正在阅读 polymer 文档,我看到了这个:
var el2 = document.createElement('input', 'my-input');
Source
暂时忘记 polymer,document.createElement
目前可以接受 2 个参数吗?与Polymer的类型扩展有关吗?
旁注:
当我用 2 个参数调用它时,Webstorm 是 "complaining"。
不可以。来自 MDN:在 HTML 文档中,Document.createElement() 方法创建指定的 HTML 元素或 HTMLUnknownElement 如果给定的元素名称未知。
var element = document.createElement(tagName);
element是创建的Element对象。
tagName 是一个字符串,指定要创建的元素的类型。创建的元素的nodeName用tagName的值初始化。
https://developer.mozilla.org/en-US/docs/Web/API/Document/createElement
目前,document.createElement
只会接受一个参数(忽略第二个)。似乎确实有一个规范允许您传递 typeExtension
,您可以阅读有关 here 的内容。 此规范仍在制定中,目前尚未在任何浏览器上以任何形式实施。
快速编辑:看来 chrome 稳定版确实包含 typeExtension
参数,可在 here 中找到。感谢@ScottMiles 的澄清。
我正在阅读 polymer 文档,我看到了这个:
var el2 = document.createElement('input', 'my-input');
Source
暂时忘记 polymer,document.createElement
目前可以接受 2 个参数吗?与Polymer的类型扩展有关吗?
旁注: 当我用 2 个参数调用它时,Webstorm 是 "complaining"。
不可以。来自 MDN:在 HTML 文档中,Document.createElement() 方法创建指定的 HTML 元素或 HTMLUnknownElement 如果给定的元素名称未知。
var element = document.createElement(tagName);
element是创建的Element对象。 tagName 是一个字符串,指定要创建的元素的类型。创建的元素的nodeName用tagName的值初始化。
https://developer.mozilla.org/en-US/docs/Web/API/Document/createElement
目前,document.createElement
只会接受一个参数(忽略第二个)。似乎确实有一个规范允许您传递 typeExtension
,您可以阅读有关 here 的内容。 此规范仍在制定中,目前尚未在任何浏览器上以任何形式实施。
快速编辑:看来 chrome 稳定版确实包含 typeExtension
参数,可在 here 中找到。感谢@ScottMiles 的澄清。