confusion over setTimeout and clearTimeout

前端 未结 3 1345
春和景丽
春和景丽 2020-12-22 05:09

I have a button that changes the background of a div when its rolled over. the background needs to change on a timer so i have used setTimout to execute methods that change

3条回答
  •  孤城傲影
    2020-12-22 05:46

    Assign a variable to your setTimeout, which you then pass to clearTimeout to clear it, i.e.

    var play_timeout = setTimeout("playV()", 2700);
    clearTimeout(play_timeout);
    

    (Note I added quotes around your first setTimeout argument)

提交回复
热议问题