JavaScript 基础二
发布日期:2021-11-15 14:57:24 浏览次数:34 分类:技术文章

本文共 1203 字,大约阅读时间需要 4 分钟。

一。javaScript中的函数

       (1)函数的调用

                 【1.可以在程序代码中调用

                     2.事件响应程序中调用函数

                    3.通过连接调用函数 

                    】

         (2)地址传递和值传递

                   【  当函数参数为数组时,采用地址传递,function里的形参发生改变时,实参也会发生改变。

                         而下文的y为基本类型变量,采用值传递,则其不受影响。

                        】

                        

<!DOCTYPE html>

<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
function  ce(a,b){
      a[0]=10;
      a[1]=20;
      a[2]=30;
      b=50;
      document.write("函数中:<br>");
    document.write("基本类型变量的值为:"+b+"<br>");
      document.write("        数组的值为:");
        for(i=0;i<x.length;i++){
            document.write(x[i]+"   ");
        }
}
</script>
</head>
<body>
 
   <script type="text/javascript" >
  var x=new Array(1,2,3);
  var y=5;
  document.write("未调用函数:<br>");
  document.write("基本类型变量的值为:"+y+"<br>");
  document.write("        数组的值为:");
  for(i=0;i<x.length;i++){
      document.write(x[i]+"   ");
  }
  document.write("<br>");
  ce(x,y);//调用函数
  document.write("<br>");
  document.write("调用函数后:<br>");
  document.write("基本类型变量的值为:"+y+"<br>");
  document.write("        数组的值为:");
  for(i=0;i<x.length;i++){
      document.write(x[i]+"   ");
  }
  </script>

</body>

</html>

        (3)函数的嵌套和递归

                     【函数的嵌套

                       1.内层函数可以使用外层函数的变量,外层不能使用内层的变量

                        2.外层函数可以调用内层函数

                       】

                        function  A(){

                                     function  B(){

                                                    } 

                                             }

                          【函数的递归

                               1.函数中直接调用该函数本身

                                2.几个函数相互调用

                              】

                                    function  A(n){

                                                   function A(n-1){

                                                                       }  

                                                   }

              (4)系统函数

                             【

                                  1.encodeURL(){不会对ASCII和数字进行编码}

                                   2.decodeURL(){解码}

                                   3.isNaN(){判断其参数是否是数字值}

                                     】

转载地址:https://blog.csdn.net/qq_39736176/article/details/81122717 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:javaScript 基础三
下一篇:javaScript 基础一

发表评论

最新留言

初次前来,多多关照!
[***.217.46.12]2024年04月07日 22时13分50秒