主题:初学者,令人费解的脚本
<html>
<head>
<title>select !</title>
</head>
<script language="vbscript">
option explicit
<!--
sub doloop()
dim c,sum
c=sum=0
do while c<101
c=c+1
sum=sum+c
if c=myform.txt.value then
exit do
end if
loop
msgbox "1+2+3+ ... +"&c&"="&sum
end sub
-->
</script>
<body>
<form name="myform">
enter: <input type="text" name="txt" size=20>
<input type="button" onClick="doloop()" value="get sum">
</form>
</body>
</html>
如入 1 结果不是 1 而是 2
结论: c=sum=0 c != 0 而是 1请大家注意,尤其是 学过c语言的朋友
<head>
<title>select !</title>
</head>
<script language="vbscript">
option explicit
<!--
sub doloop()
dim c,sum
c=sum=0
do while c<101
c=c+1
sum=sum+c
if c=myform.txt.value then
exit do
end if
loop
msgbox "1+2+3+ ... +"&c&"="&sum
end sub
-->
</script>
<body>
<form name="myform">
enter: <input type="text" name="txt" size=20>
<input type="button" onClick="doloop()" value="get sum">
</form>
</body>
</html>
如入 1 结果不是 1 而是 2
结论: c=sum=0 c != 0 而是 1请大家注意,尤其是 学过c语言的朋友