JavaScript009, function

<! DOCTYPE HTML > 
< HTML > 
    < head > 
        < Meta charset = "UTF-. 8" > 
        < title > the JavaScript function </ title > 
    </ head > 
    < body > 
        < H3 > the JavaScript Function (Function: Function) </ H3 > 
        <! -  
        functions are event driven or reusable blocks of code when it is executed and. 
         Syntax: 
         function testFun () {// begin function, testFun () - function name 
             block 
         } 
         -> 
        <Call the function with parameters </ h4 > 
        < the Button of the type = "the Button" onclick = "myFunction ( 'dog left', 22)" > point I </ the Button > 
        <-! Here's dog left, 22 is the argument, you can use different parameters to invoke the function; -> 
        < P ID = "Demo" style = "Color: Red;" > </ P > 

        < Script type = "text / JavaScript" > 
            / * invoke the parameterized function (min form and actual parameters) * / 
            function myFunction (name, age) { // name here, age is the parameter; 
                Document.getElementById('demo' ) .InnerHTML = name +  ' has '  + Age +  ' years old! ' ; 
            } 
        </ Script > 
        < P > ---------------------- < / P > 

        < H4 > return value </ H4 > 
        <-! return value of the function may be implemented to return to the calling function; -> 
        < P ID = "the demo1" style = "Color: Red;" > </ P > 

        < Script of the type = "text/javascript">
            function MyFunction1 (X, Y) {
                 IF (X > Y) {
                     return X + Y; / * when x> y, returns the value of x + y, end function is not performed * Y X * / 
                } 
                return X * Y; / * when x <y, returns the value of x * y * / 
            } 
            document.getElementById ( ' the demo1 ' ) .innerHTML = MyFunction1 ( . 5 , . 4 );
         </ Script > 
        < P > ------ ---------------- </ the p-> 
        
            <! - Variable 
            variables into local and global variables; 
                called local variables declared in the variable var function; 
                variable outside the function, the script tag is called a global variable declarations; 
            life cycle: 
                the local variable is declared starting from to the end of the function; 
                the global variable is declared closed from the beginning to the page; -> 
    </ body > 
</ HTML >

Guess you like

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