一。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(){判断其参数是否是数字值}
】