<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script type="text/javascript">
//需求:编写一个函数,用于计算所有参数相加的和并返回
function sum(num1, num2){
var result = 0;
for(var i = 0; i < arguments.length; i++){
if(typeof(arguments[i]) == "number"){
result += arguments[i];
}
}
return result;
}
alert(sum(1, 2, 3, 4, 5));
</script>
</head>
<body>
</body>
</html>
JavaScript 隐形参数
最新推荐文章于 2024-03-28 21:21:23 发布