<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>阶乘计算器</title>
</head>
<body>
<form>
<input type="text" id='number1' />
<button type="submit" onclick='factorial()'>Submit</button>
<br />
<input type="text" id='number2' />
</form>
<script type="text/javascript">
function factorial(){
var num1=parseInt(document.getElementById('number1').value);
var num2=document.getElementById('number2').value;
if (num1<=1) {
num2=1;
}
else{
num2=num1*arguments.callee(num1-1);
}
}
</script>
</body>
</html>
1 回答
已采纳
qq___524
TA贡献171条经验 获得超74个赞
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>阶乘计算器</title> </head> <body> <form action=""> <input type="text" id='number1' /> <button type="submit" onclick='fun()'>Submit</button> <br /> <input type="text" id='number2' /> </form> <script type="text/javascript"> function factorial(num1){ var num2; if (num1<=1) { num2=1; } else{ num2=num1*arguments.callee(num1-1); } return num2; } function fun(){ var num1=parseInt(document.getElementById('number1').value); document.getElementById("number2").value=factorial(num1); } </script> </body> </html>
添加回答
举报
0/150
提交
取消