如何在使用onclick事件调用另一个函数时禁用javascript中的函数?

时间:2017-08-02 15:11:43

标签: javascript slider

我是javascript的初学者,有这个问题。我有一个滑块在加载窗口时自动运行,我也有prev和下一个按钮。问题是,当我单击按钮时,滑块会自动运行。如何在单击按钮时禁用使我的幻灯片自动的功能? 这是我的HTML:

<div class="slider-wrapper"> 
    <img src = "images/slide/slide1.jpg" id="adSlide"/>
</div>



<div class="slider-button-wrapper" >
    <button type="button" value="previous" id="blackleft" onclick="processPrevious()" ><p>&lt;</p></button>
    <button type="button" value="next" id="blackright" onclick="processNext()"><p>&gt;</p></button>
</div>  

和javascript代码:

              window.onload = rotate;
     var thisSlide=0;

function rotate(){
var adImages = new Array("images/slide/slide1.jpg", 
                        "images/slide/slide2.jpg",
                        "images/slide/slide3.jpg",
                        "images/slide/slide4.jpg",
                        "images/slide/slide5.jpg");
thisSlide++;

if(thisSlide == adImages.length){
    thisSlide=0;
}

document.getElementById("adSlide").src = adImages[thisSlide];

setTimeout(rotate, 3 * 1000);
}



var myPics = new Array("images/slide/slide1.jpg", 
                        "images/slide/slide2.jpg",
                        "images/slide/slide3.jpg",
                        "images/slide/slide4.jpg",
                        "images/slide/slide5.jpg");

function initButtons(){
    document.getElementById("blackleft").onclick = processPrevious;
    document.getElementById("blackright").onclick = processNext;
}

 function processPrevious(){
     if (thisSlide == 0){
        thisSlide = myPics.length;
  }
    thisSlide--;
    document.getElementById("adSlide").src = myPics[thisSlide];
    return false;
}

 function processNext(){
    thisSlide ++;
    if (thisSlide == myPics.length){
    thisSlide = 0;
  }

   document.getElementById("adSlide").src = myPics[thisSlide];
   return false;
  }

0 个答案:

没有答案