??? ??????
JavaScript for ??? ?? ??? ????? ???? ? ?????. ??? ??? ????.
for (expr1; ?? ????? 1~10? ?????. <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>php中文網(wǎng)(php.cn)</title>
<script type="text/javascript">
var i=1
for (i = 1; i <= 10; i++) {
document.write(i + "<br />")
}
</script>
</head>
<body>
</body>
</html>
?? ??:
2
34
567
8
9
10
for ?? ?? ??
? ?? ??? ??(expr1)? ?? ?? ?? ??? ? ? ?????.
expr2? ?? ?? ?? ?????. ? ??? ?? ?? TRUE?? ??? ???? ?? FALSE?? ??? ?????.
expr3? ? ?? ?? ??(??)???.
? ???? ?? ?? ? ????. expr2? ?? ??? ??? ??? ????? ?? ?? ?? break? ??? ??? ? ????.
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文網(wǎng)(php.cn)</title> <script type="text/javascript"> var i=1 for (i = 1; ; i++) { if (i > 10) { break; } document.write(i + "<br />"); } </script> </head> <body> </body> </html>
? ?? ??? 1~10? ????? if ??? ???? i>10? ? ?????. ??? ????.
Tips???? ??? ?, ????? ????? ?? ????? "??"? ??? ??? ???? ???. ?? ?? ??(?? ?? ???)?? ??? ???? ???. ?? ??? ????? ????.
For/In LoopJavaScript for/in ?? ??? ??? ?????.
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文網(wǎng)(php.cn)</title> </head> <body> <button onclick="myFunction()">點(diǎn)擊這里</button> <p id="demo"></p> <script> function myFunction(){ var x; var txt=""; var person={fname:"Bill",lname:"Gates",age:56}; for (x in person){ txt=txt + person[x]; } document.getElementById("demo").innerHTML=txt; } </script> </body> </html>