如何在 JavaScript 中重置间隔 onclick。我有以下教程,一切正常,我可以让杂耍在点击时重新开始。
var myImage = document.getElementById("mainImage");
var imageArray = ["_images/overlook.jpg","_images/winery_sign.jpg","_images/lunch.jpg",
_images/bigSur.jpg","_images/flag_photo.jpg","_images/mission_look.jpg"];
var imageIndex = 0;
function changeImage (){
myImage.setAttribute("src",imageArray [imageIndex]);
imageIndex++;
if (imageIndex >= imageArray.length){
imageIndex = 0;
}
}
var intervalHandler = setInterval(changeImage, 5000);
myImage.onclick = function (){
clearInterval(intervalHandler);
}
**// The code below doesn’t work**
var intervalReset = clearInterval;
myImage.onclick = function (){
setInterval(intervalReset);
};