日期:2014-05-17  浏览次数:20889 次

asp求和问题,需要高手哦!
我的本意是想设计一个求 任意的2个数的和或者说,任意2个数字之间的和,比如,1加到100的和或者100加到600的和,总之这个2个数可以是只有2个数,也可以有很多数相加!



<BODY>
  <p align ="center"></p>
  <form name = "form1" method ="post" action ="">
  <p>请输入求和范围 </p>
  下限<input name ="tlow" type= "text" id ="tlow" size ="10">上限<input name ="
  thigh" type ="text" id ="thigh" size ="10">
  <input type ="submit" name ="submit" value ="求和"
  </form>
  <%
Dim i, sum,low,high
sum=0
low=request("tlow")
high=request("thigh")
For i=low To high
sum= sum + i
Next
response.write"sum from "& low &"to" & high &"is:"& sum
 %>
 </BODY> 



------解决方案--------------------
asp版本:
VB code
<form name = "form1" method ="post" action ="">
    <p>请输入求和范围 </p>
    下限<input name ="tlow" type= "text" id ="tlow" size ="10" onkeypress="this.value=this.value.replace(/[^\d]/g,'')" />
    上限<input name ="thigh" type ="text" id ="thigh" size ="10" onkeypress="this.value=this.value.replace(/[^\d]/g,'')" />
    <input type ="submit" value ="求和">
</form>
<%
dim tlow,thigh,n,i
tlow=request.form("tlow")
thigh=request.form("thigh")
if tlow<>"" and thigh<>"" then
    if tlow>thigh then
        Response.write "不能这样的"
    else
        n=0
        for i=tlow to thigh
            n=n+i
        next
        Response.write tlow&"累加"&thigh&"="&n
    end if
end if
%>

------解决方案--------------------
揪心,你不是都写出来了么
------解决方案--------------------
呵呵,楼主太没自信了吧,你不是都写好了嘛,只是没加上判断而已,只要再耐心往下想一下应该就完美了。