03.JavaScript流程控制語句

/*
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比較容易入門,就不再作演示了

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章