定时器


var btn1=document.getElementById('btn1');
var btn2=document.getElementById('btn2');
var fn4='';

 btn1.onclick=function () {
    fn4=setInterval(function () {
        var x=parseInt(Math.random()*100+1);
        var y=parseInt(Math.random()*100+1);
        dv.style.left=x+'px';
        dv.style.top=y+'px';
    },10);

};
btn2.onclick=function () {
    clearInterval(fn4);


    var im=document.getElementById('im');
    function fn1() {
        var td=new Date();
        var hour=td.getHours();
        var second=td.getSeconds();
        hour=hour<10?'0'+hour:hour;
        second=second<10?'0'+second:second;
        im.src="meimei/"+hour+'_'+second+".jpg";
    }
    fn1();
    setInterval(fn1,1000);

你可能感兴趣的:(定时器)