猿问

想用递归实现一个阶乘计算器,大神帮忙看看问题出在哪?

<!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>


garnett555
浏览 1372回答 1
1回答

qq___524

<!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>
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答