提供后一个不正确的答案 https://stackoverflow.com/questions/36105267/js-accessing-event-data-via-a-string-to-dictate-which-input-forms-to-be-captur/36105392#36105392关于.item()
的财产Node.childNodes https://developer.mozilla.org/en-US/docs/Web/API/Node/childNodes对于一个问题,我检查了__proto__
归来的childNodes
of a form
元素并找到一个forEach
method.
The forEach
的方法Node.childNodes
没有记录在规范中NodeList https://www.w3.org/TR/domcore/#nodelist, in Methods at MDN https://developer.mozilla.org/en-US/docs/Web/API/Node/childNodes, or 接口节点列表 https://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#ID-536297177,并且似乎没有被提及使用 forEach 方法迭代 NodeList https://stackoverflow.com/questions/21921282/iterate-a-nodelist-using-foreach-method或链接到该问题的页面;尽管它似乎在 Chromium 50 中可用。
该方法是否仅适用于相对较新版本的 Chrome / Chromium?如果是,这是否有记录?
有没有相关文件forEach()
的方法Node.childNodes
?
document.querySelector("form").addEventListener("submit", function(e) {
e.preventDefault();
var form = e.target;
form.childNodes.forEach(function(el) {
if (el.tagName === "INPUT" && el.type !== "submit")
snippet.log("name:" + el.name + ", value:" + el.value)
});
});
<form>
<input type="text" name="firstName" value="The first name">
<input type="text" name="lastName" value="The last name">
<input type="email" name="emailAddress" value="[email protected] /cdn-cgi/l/email-protection">
<br>
<input type="submit" value="Submit">
</form>
<!-- Script provides the `snippet` object, see http://meta.stackexchange.com/a/242144/134069 -->
<script src="//tjcrowder.github.io/simple-snippets-console/snippet.js"></script>
DOM4 现在定义NodeList https://www.w3.org/TR/dom/#nodelist作为一个可迭代的:
iterable<Node>;
根据IDL草案 http://heycam.github.io/webidl/#idl-iterable,这意味着
An 界面 http://heycam.github.io/webidl/#dfn-interface可以声明为iterable通过使用可迭代声明(匹配Iterable http://heycam.github.io/webidl/#prod-Iterable)在界面主体中。
iterable<value-type>;
iterable<key-type, value-type>;
实现声明为可迭代的接口的对象
支持迭代以获得一系列值。
Note:在 ECMAScript 语言绑定中,一个接口是
iterable 将具有“entries”、“forEach”、“keys”、“values” 和@@迭代器 https://people.mozilla.org/~jorendorff/es6-draft.html#sec-well-known-symbols其上的属性接口原型对象 http://heycam.github.io/webidl/#dfn-interface-prototype-object.
如果给出单个类型参数,则该接口有一个价值
迭代器并提供指定类型的值。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)