调用方式2
2025年4月30日小于 1 分钟
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>函数调用</title>
</head>
<body>
<!-- 第二种调用方式 -->
<button onclick="fa()">点击调用</button>
<script type="text/javascript">
//在js中定义变量的时候 不能跟函数名 冲突 否则会覆盖函数
//第一种直接在代码中调用
doo();
function doo()
{
alert('直接调用!');
}
//打开如下注释代码时下方调用会报错的!!!!!! 上方调用不会
var doo=100;
//doo();
//在触发事件中
//注意尽量在上方写事件,在下方有时不显示
function fa()
{
alert('在触发事件中调用');
}
//第三种 赋值给变量调用 注意要在变量声明以后调用
//into(); △
var into=new Function('x','y','alert(x+y)');
into(10,20);
into(10);
into(10,30,40);
</script>
</body>
</html>