javascript:为什么这不会导致页面上的所有表单都重置? [英] javascript: why won't this cause all the forms on a page to reset?

查看:57
本文介绍了javascript:为什么这不会导致页面上的所有表单都重置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

晚安同伴们:

我知道这应该很简单,但是我很累,只想把它做好.这就是我认为应该完成的方式,与

i know it should be simple, but i'm tired and just want to get it done. this is how i thought it should be done, which is identical to how this fellow did it, BUT numberOfForms comes up ZERO, instead of THREE (that's how many forms are on the page, all named & id'd). what did i miss?

var numberOfForms = document.getElementsByTagName("form");
console.log("numberOfForms: " + numberOfForms);
for (var i=0; i<numberOfForms.length; i++)
{
  document.forms[i].reset;
}

请照亮,PLZ.然后我就可以猛扑过去了.

shed some light, plz. then i can punch out and hit the hay.

推荐答案

尝试一下.您已经有了一个包含所有HTML DOM Form元素的数组.使用 numberOfForms [i] .reset()而不是尝试使用 document.forms [n] .

Try this. You have already got an array with all HTML DOM Form elements. Use numberOfForms[i].reset() instead of trying to use document.forms[n].

var numberOfForms = document.getElementsByTagName("form"); 
console.log("numberOfForms: " + numberOfForms); 
for (var i=0; i<numberOfForms.length; i++) 
{ 
   numberOfForms[i].reset();
} 

实际上,这更清洁,更高效,实际上不需要使用 document.getElementsByTagName()

Actually this is cleaner and more efficient, there is actually no need to traverse the DOM with document.getElementsByTagName()

var allForms = document.forms;
for (var i=0; i < allForms.length; i++) {
  allForms[i].reset();
}

这篇关于javascript:为什么这不会导致页面上的所有表单都重置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆