关于setTimeout跟setinterval的一些基本的用法/小常识

来源:互联网 发布:市场调研软件 编辑:程序博客网 时间:2024/06/15 16:27

//关于setTimeout 一些小常识 setTimeout(youfunction,3000)  //是只执行一次 setinterval(youfunction,3000) //是在当前页面一直执行 1000= 1秒写法的//参数 以及方法var  oder  ='11233';function selectoder(oder){        $.post('YOUAPI.php',{'tradeno':oder},function(res){           if(res.success){               layer.alert(res.message,function(){                   window.location.reload();               });           }else{               setTimeout(function(){                   selectoder(oder);               },3000);           }        }); }//错误的写法setTimeout(selectoder(oder),3000);//这里缺少闭包函数  如果直接一直写下去的话呢会不停的循环执行 //所以需要写一个匿名的闭包函数 setinterval 也是一样 //正确的写法  setTimeout(function(){                   selectoder(oder);               },3000);


原创粉丝点击