输入框输入是“奇数”的就相加,输入总和
各老师:在5个输入框(名称:INPUT1,INPUT2,INPUT3,INPUT4,INPUT5)中随机输入5个数,当输入的是奇数时,就累加,最后输出总和。怎么实现?谢谢!
<html> <head> <title>奇数循环相加</title> <script language="javascript"> //表单提交 function form1_Submit() { document.form1.action=self.location.href;//提交到当前页 document.form1.target="_self";//提交到当前框架 document.form1.submit();//提交表单 } function Page_Load() { <% Dim i,IsInt,Total,txtCount IsInt=True Total=0 Function IsInteger(val) On Error Resume Next IF VarType(CInt(Val))<>2 Then IsInteger=False Else IsInteger=True End IF End Function txtCount=Request.Form("txt_Num").Count IF Request.Form("IsSubmit")="True" Then '第一次循环验证是否都是整数 For i=1 To txtCount IF IsInteger(Request.Form("txt_Num")(i))=False Then IsInt=False End IF Next IF IsInt=False Then Response.Write "alert('不可以输入非整数');" Else '第二次循环累加奇数和 For i=1 To txtCount IF CInt(Request.Form("txt_Num")(i)) Mod 2<>0 Then Total=Total+CInt(Request.Form("txt_Num")(i)) End IF Next Response.Write "alert('奇数和为"&Total&"');" End IF End IF %> } </script> </head> <body onload="Page_Load();"> <form name="form1" method="post" > <% Dim t,txtNum'声明变量 txtNum=5'文本框个数 Response.Write "请输入"&txtNum&"个整数</BR>" '循环输出文本框 For t=0 To txtNum Response.Write "<input type=text name=txt_Num /></br>" Next %> <input type="hidden" name="IsSubmit" value="True" /> <input type="button" name="Submit" onClick="form1_Submit();" value="提交" /> </form> </body> </html>