梦之都
JavaScript教程
JavaScript自增、自减运算符与表达式
示例
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>JavaScript自增、自减运算符与表达式示例</title> </head> <body> <script type="text/javascript"> var a; var i=6; //(前加加)i加1后,i等于7,并将i值赋予a,于是a等于7 a=++i; document.write("i="+i+"<br />"); document.write("a="+a+"<br />"); i=6; //(后加加)将i值赋予a,于是a等于6,最后i加1,i等于7 a=i++; document.write("i="+i+"<br />"); document.write("a="+a); </script> </body> </html>