码迷,mamicode.com
首页 > 其他好文 > 详细

递归 间隔 延迟

时间:2017-06-18 23:40:27      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:功能   程序   后退   input   ++   自身   一段   star   com   

递归是程序调用自身的编程技巧称为递归法

用递归法求一下文件夹里的文件数量:

 <script type="text/javascript">
    //给一个文件夹,求该文件夹下所有文件的数量
    //函数功能明确:给我一个文件夹,返回该文件夹下文件的数量
    function shuLiang(文件夹路径){
        
        var sum = 0;
        打开文件夹遍历该文件夹下的文件
        if(是文件){
            sum++;
        }else{
            sum = sum + shuLiang(文件夹的路径);
        }
        
        return sum;
    }
</script> 
 
  间隔执行一段代码(函数):window.setlnterval("要执行的代码",间隔的毫秒数)
  间隔:

window.setInterval("要执行的代码",间隔的毫秒数) 
window.clearInterval(间隔的id); 循环一次之后用来清除隔几秒执行的代码

?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
    <input type="button" value="开始" onClick="start()" />
    <input type="button" value="停止" onClick="end()" />
</body>
</html>
<script>
    function show(){
        alert("hello");
    }
    var id;
    function start(){
        id = window.setInterval("show()",1000);
    }
    function end(){
        window.clearInterval(id);
    }
</script>
?

 延迟一段时间执行某一段代码(函数):window.setTimeout("要执行的代码",延迟的毫秒数)
使用延迟来做到间隔的效果:

    function show(){
        alert("hello");
        window.setTimeout("show()",1000);
    }
    show();

Windows.history对象
windows.history.go(n);  n 如果是正数则代表前进 n 个页面, n 如果是负数则代表后退 n 个页面。
 
Window.location对象
window.location.href="http://www.baidu.com";修改页面的地址,会跳转页面(页面重新定向)。 

递归 间隔 延迟

标签:功能   程序   后退   input   ++   自身   一段   star   com   

原文地址:http://www.cnblogs.com/dongtian1992/p/7045649.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!