javascript遍历验证所有文本框的值

要求:

遍历所有文本框的值并判断是否为数字

思路:

大家知道文本框input的type为text,所有我们只要遍历所有input,判断其type是否为text,然后再判断指定字段的值即可达到要求

具体代码如下:

var aa = document.getElementsByTagName("input");
var bb = 0;
for(var i=0;i<aa.length;i++)
{
var avalue = aa[i].value;
var atype = aa[i].type;
if(atype == "text")
bb++;
}
alert("共有"+bb+"项text")

http://www.corange.cn/archives/2008/11/2201.html

原文地址:https://www.cnblogs.com/zerogo/p/2209130.html