【技术】数学中的阶乘

0!=1,
1!=1,
2!=2,
3!=6,
4!=24,
5!=120,
6!=720,
7!=5,040,
8!=40,320
9!=362,880
10!=3,628,800
 
 
 

<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>test4</title>
    <script src="js/jquery-1.11.1.min.js"></script>
  </head>
  <body>
    <input type="text" name="" id='text' value="">
    <button id='but'>提交</button>

    <script>

    $("#but").click(function(){

      //val() 方法返回或设置被选元素的值。(返回input的值)
      var txt = $('#text').val();

      //isNaN() 函数用于检查其参数是否是数字值。
      if (txt!==""&&!isNaN(txt)) {
        console.log(jx(txt));
      }else{
      alert('请输入数字。。。');
      }

    });

 

    function jx(num){

    // 因为0!=1

    //所以num<1时,return 1
      if(num<=1){
        return 1;
      }
      return num*jx(num-1);
    }

    </script>

  </body>
</html>

posted @ 2014-09-13 23:00  ybingbing_1213  Views(257)  Comments(0)    收藏  举报