JavaScript012, judgment statement

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>JavaScript 判断语句</title>
    </head>
    <body>
        <h3>JavaScript 之 if...else</h3>
        <button type="button" onclick="ifElse()">点我</button>
        
        <p>---------------------</p>
        
        < H3 > JavaScript's switch statement </ h3 > 
        <-! Switch based on different conditions to perform different actions. -> 
        < the Button of the type = "the Button" onclick = "SWIT ()" > point I </ the Button > 
        < the p- the above mentioned id = "Demo" > </ the p- >
        
        < Script type = "text / JavaScript" > 
            function IfElse () {
                 var FDate =  new new a Date () getHours ();. // DATE () acquisition time, getHours () h reacquisition 
                IF (FDate <  24  && FDate >  18 is ) { // FDate <24 and> 18 is 
                    Alert ( " good evening! " ); // satisfies this condition is executed 
                }
                 the else  IF (FDate ==  12 is ) {
                    Alert ( " Good afternoon! " ); // satisfies this condition is executed 
                }
                 the else {
                    Alert ( " now: "  + a Date ()); // does not satisfy the conditions for the implementation of I 
                }
                 / * IF statement can stand alone, that is, do not need else if and the else * /
            }
            
            /* ---------------------- */
            
            function SWIT () {
                 var Time =  new new a Date () getDay ();. // getDay (), acquiring the week 
                / * var X; * / 
                Switch (Time) {
                     / * the relationship between the case and is == Time =, according to the execution of a value corresponding case Time * / 
                    Case  0 : X =  " today is Sunday " ; // the Sunday (Sunday) = 0 
                    BREAK ;
                     Case  . 1 : X =  " today is Monday " ;
                     BREAK ;
                     Case  2 : x=  " Today is Tuesday " ;
                     BREAK ;
                     Case  3 : the X- =  " Today is Wednesday " ;
                     BREAK ;
                     Case  4 : the X- =  " Today is Thursday " ;
                     BREAK ;
                     Case  5 : the X- =  " Today is Friday " ;
                     BREAK ;
                     default : the X- =  " today is Saturday " ;// When Time does not match all of the above case will execute default 
                }
                document.getElementById("demo").innerHTML = x;
            }
        </script>
    </body>
</html>

Guess you like

Origin www.cnblogs.com/zhou0910/p/12121775.html