03.JavaScript流程控制语句

    技术2024-08-01  74

    /* js流程控制语句: 1)if...else 2)for循环控制语句 3)switch循环语句 */ function centent_if() { var x = 12; if(x>18){ alert("恭喜你,你成年了"); }else{ alert("很抱歉,你还是个胖娃娃..."); } } function content_for(){ for(var i=0;i<=12;i++){ alert(i); } } function table_test() { document.getElementById("table_test").innerHTML = "" + "<table>" + " <tr style='background-color: aqua'>" + " <td>&nbsp;</td> " + " <td>&nbsp;</td> " + " <td>&nbsp;</td> " + " </tr>" + " <tr style='background-color: antiquewhite'>" + " <td>&nbsp;</td> " + " <td>&nbsp;</td> " + " <td>&nbsp;</td> " + " </tr>" + " <tr style='background-color: blueviolet'>" + " <td>&nbsp;</td> " + " <td>&nbsp;</td> " + " <td>&nbsp;</td> " + " </tr>" + "</table>"; } function content_switch() { var x = 12; switch (x) { case 10: alert("x="+x); break; case 12: alert('x:'+x); break; default: alert('None'); break; } } function content_while() { while (true){ window.console.log("aaaaa"); window.console.log("aaaaa"); window.console.log("aaaaa"); break; } }

    鉴于js比较容易入门,就不再作演示了

    Processed: 0.014, SQL: 9