<!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=mymoney++;
}
document.write(sum);
</script>
</head>
<body>
</body>
</html>
var mymoney,sum=0;//mymoney变量存放不同面值,sum总计 for(mymoney=1;mymoney<=10;mymoney++) { sum=mymoney++; document.write(sum);//测试sum分别输出1,3,5,7,9,这里的mymoney++的特性,先把初始值赋值给sum,之后再进行加一,然后再一(循环迭代); }
document.write(mymoney); 这就是10了
你写的是mymoney++,你用++mymoney试试
++在后是先进行运行再进行自加,++在前是先自加再进行运算
mymoney初始化为0