js教程系列17:javasc函数

1 释义:函数是由事件驱动的或者当它被调用时执行的可重复使用的代码块。

2 格式:通过 function  关键字.

function test(){
     alert("您好");
}    

3 方法的调用:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script type="text/javascript">
        function test(){
         alert("您好");
           }  
        test();

    </script>
</head>
<body>
    
</body>
</html>

4 举个例子:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script type="text/javascript">
         function min(a,b){
             if(a<b){
                 alert(a);
             }else
             {
                 alert(b);
             }
         }
         min(1,2);
    </script>
</head>
<body>
    
</body>
</html>

 

猜你喜欢

转载自www.cnblogs.com/autoXingJY/p/8862423.html
今日推荐