<!doctype html> <html> <head> <meta charset="utf-8"> <title>for循环</title> <script type="text/javascript"> var mymoney,sum=100;//mymoney变量存放不同面值,sum总计 for(mymoney=1;mymoney<=10;mymoney++) { sum= sum + mymoney; } document.write("sum合计:"+sum); </script> </head> <body> </body> </html> <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>if...else</title> <script type="text/JavaScript"> var mymoney,sum=0;//mymoney变量存放不同面值,sum总计 for(mymoney=1;mymoney<=10;mymoney++) { sum= sum + mymoney; } document.write("sum合计:"+sum); </script> </head> <body> </body> </html>
= =..因为你的sum一个初值是100,一个是0啊。。