JavaScript 函数的调用
🌙
手机阅读
本文目录结构
函数的调用
1.直接调用: 函数名(实参列表)
function test1(arg1,arg2){
console.log("function语句的定义方法:",arg1+arg2);
return;
}
//直接调用
test1(1,2);//function语句的定义方法: 3
2.在链接中调用
<body>
<button type="button" name="button" onclick="test1(9,9)">click me</button>
<script>
function test1(arg1,arg2){
console.log("function语句的定义方法:",arg1+arg2);
return;
}
</script>
</body>
3.在事件中调用
<body>
<button type="button" name="button" id="btn1">click me</button>
<script>
var oBtn1=document.getElementById("btn1");
oBtn1.onclick=function(){
test1(2,2)
};
function test1(arg1,arg2){
console.log("function语句的定义方法:",arg1+arg2);
return;
}
</script>
</body>
4.递归调用
在函数内部调用函数自身
<button type="button" name="button" id="btn1">click me</button>
<script>
var oBtn1=document.getElementById("btn1");
oBtn1.onclick=function(){
test1(10,1);
};
function test1(arg1,arg2){
console.log("最开始的调用方法",arg1+arg2);
arg1--;
if(arg1>0){
test1(arg1,arg2)
}
return;
}
</script>
函数的调用还是非常灵活的;