下面是个简单易学的JAVASCRIPT里的函数递归用法教程,图老师小编详细图解介绍包你轻松学会,喜欢的朋友赶紧get起来吧!
【 tulaoshi.com - Web开发 】
在编写JAVASCRIPT代码过程中,有时候会经常对函数进行自调用,也就是函数递归,
JAVASCRIPT允许函数递归,但是有其自己的递归原则,
(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/webkaifa/)view plaincopy to clipboardprint?
mce:script type="text/javascript"!--   
var type=6;   
    function current(a)   
    {   
        var i=0;   
        if(a==undefined)   
            {   
                current(1);   
                return;   
            }   
        if(document.getElementById("cursors"+a)==null&&typea)   
        {   
            current(a*2);   
            return;   
        }   
        var value=1;   
         while(type=value)   
         {   
            obj=document.getElementById("item"+value);   
            if(obj!=null)obj.className='hidden';   
               
            obj=document.getElementById("cursors"+value);   
            if(obj!=null)obj.className='behind';   
            i++;   
            value=Math.pow(2,i);   
         }   
         if((obj=document.getElementById("item"+a))!=null)obj.className='show';   
         if((obj=document.getElementById("cursors"+a))!=null)obj.className='current';   
              
    }   
// --/mce:script  
mce:script type="text/javascript"!--
var type=6;
    function current(a)
    {
        var i=0;
        if(a==undefined)
            {
                current(1);
                return;
            }
        if(document.getElementById("cursors"+a)==null&&typea)
        {
            current(a*2);
            return;
        }
        var value=1;
         while(type=value)
         {
            obj=document.getElementById("item"+value);
            if(obj!=null)obj.className='hidden';
            
            obj=document.getElementById("cursors"+value);
            if(obj!=null)obj.className='behind';
            i++;
            value=Math.pow(2,i);
         }
         if((obj=document.getElementById("item"+a))!=null)obj.className='show';
         if((obj=document.getElementById("cursors"+a))!=null)obj.className='current';
           
    }
// --/mce:script 
请看current函数,函数体内嵌套了递归,这里是单项运行,即递归一次后便用return结束运行,
当然你也可以递归完后继续运行,JAVASCRIPT不排斥这个!
(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/webkaifa/)使用递归可以让你的代码看起来更完整,但是千万小心不能让他陷入死循环
来源:http://www.tulaoshi.com/n/20160219/1611586.html
看过《JAVASCRIPT里的函数递归用法》的人还看了以下文章 更多>>