如何用Javascript实现获取 多个文本输入框里面的数,然后再把他们相加
1个回答
展开全部
实现此功能的整个网页源代码如下:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Javascript实现获取 多个文本输入框里面的数,然后再把他们相加</title>
</head>
<body>
<script language="javascript" type="text/javascript">
<!--
function count(){
var v1=parseInt(document.form1.v1.value);
var v2=parseInt(document.form1.v2.value);
var v3=parseInt(document.form1.v3.value);
var v4=parseInt(document.form1.v4.value);
var v5=parseInt(document.form1.v5.value);
var v6=parseInt(document.form1.v6.value);
var v7=v1+v2+v3+v4+v5+v6;
document.form1.v7.value=v7;
alert(v1+" + "+v2+" + "+v3+" + "+v4+" + "+v5+" + "+v6+" = "+v7);
}
--></script>
<form name="form1" id="f1" method="post" action="">
<input type="text" size="10" name="v1" id="v1"> +
<input type="text" size="10" name="v2" id="v2"> +
<input type="text" size="10" name="v3" id="v3"> +
<input type="text" size="10" name="v4" id="v4"> +
<input type="text" size="10" name="v5" id="v5"> +
<input type="text" size="10" name="v6" id="v6"> =
<input type="text" size="10" name="v7" readonly="true" id="v7"><br /><br /><input name="sum" onClick="count()" value="给我算!" type="button">
</form>
</body>
</html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Javascript实现获取 多个文本输入框里面的数,然后再把他们相加</title>
</head>
<body>
<script language="javascript" type="text/javascript">
<!--
function count(){
var v1=parseInt(document.form1.v1.value);
var v2=parseInt(document.form1.v2.value);
var v3=parseInt(document.form1.v3.value);
var v4=parseInt(document.form1.v4.value);
var v5=parseInt(document.form1.v5.value);
var v6=parseInt(document.form1.v6.value);
var v7=v1+v2+v3+v4+v5+v6;
document.form1.v7.value=v7;
alert(v1+" + "+v2+" + "+v3+" + "+v4+" + "+v5+" + "+v6+" = "+v7);
}
--></script>
<form name="form1" id="f1" method="post" action="">
<input type="text" size="10" name="v1" id="v1"> +
<input type="text" size="10" name="v2" id="v2"> +
<input type="text" size="10" name="v3" id="v3"> +
<input type="text" size="10" name="v4" id="v4"> +
<input type="text" size="10" name="v5" id="v5"> +
<input type="text" size="10" name="v6" id="v6"> =
<input type="text" size="10" name="v7" readonly="true" id="v7"><br /><br /><input name="sum" onClick="count()" value="给我算!" type="button">
</form>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询