问题:
我们向知道如何获取所有的type为button按钮的input域。
实现方法及源码:
document.mathForm获取所有表单的所有input域,然后使用document.mathForm.elements[x]获取每个input域,x表示索引,从0开始。再使用document.mathForm.elements[x].type获取每个域的type属性值,如果type属性值为button,则表示该input域为按钮button。
源码如下:
<html>
< language=\" \">
var buttonCount = 0;
<!--from http://www.manongjc.com 码农教程 -->
for(var x=0; x<document.mathForm.length; x++)
{
if(document.mathForm.elements[x].type==\"button\")
buttonCount++;
}
document.write(\"Please select one of the \",buttonCount);
document.write(\" buttons above to find out the answer to the math problem.\");
</ >
<form name=\"mathForm\">
<input type=\"button\"
name=\"4plus2\"
value=\"(4 + 2)\"
=\"document.mathForm.answer.value=\'(4 + 2) = 6\'\">
<input type=\"button\"
name=\"4minus2\"
value=\"(4 - 2)\"
=\"document.mathForm.answer.value=\'(4 - 2) = 2\'\"><HR>
Answer:
<input type=\"text\" name=\"answer\">
</form>
</html>
本文章向大家介绍了如何使用document.mathForm.elements[x].type来判断input域是否为button。
继续阅读与本文标签相同的文章
-
5G核心网建设是采用SA独立组网还是NSA独立组网
2026-05-15栏目: 教程
-
买了iPhone手机,旧设备上数据怎样迁移,这有3种办法快速解决
2026-05-15栏目: 教程
-
昔日电商巨头轰然倒塌!烧光几十亿补贴后,欠下工资5600万
2026-05-15栏目: 教程
-
从做流量的梦到踏实做生意,小程序成为互联网逆袭工具!
2026-05-15栏目: 教程
-
Uber在巴黎上线摩托车租赁服务,加速共享两轮布局对击Lyft
2026-05-15栏目: 教程
