setInterval() 方法


setInterval()是一个函数

简单示例:

setInterval(function(){
alert("hello world"), },1000);

 意思是每1000毫秒弹出“hello world"

 

字符串的形式调用函数名,这种写法调用函数名是不能传参的:

setInterval("hello()",5000);
  function hello(){
    alert("hello");
  }

把要执行的代码以字符串形式放在setInterval()的参数里,它可以传参数

var a = "hello";
    setInterval("alert('"+a+"')",5000);

不以字符串的形式调用函数名,使用它传递参数相对比较清晰

setInterval(function(){
        hello("hello");
    },5000);

    function hello(word){
        alert(word);
    }

  

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM