<div class="slider">
<div class="slides">
<input type="radio" name="radio-button" id="radio1">
<input type="radio" name="radio-button" id="radio2">
<input type="radio" name="radio-button" id="radio3">
<input type="radio" name="radio-button" id="radio4">
<input type="radio" name="radio-button" id="radio5">
<input type="radio" name="radio-button" id="radio6">
<div> <div id="next"><</div>
<div id="previous">></div> <div class="navigation-manual">
<label for="radio1" class="manual-button"></label>
<label for="radio2" class="manual-button"></label>
<label for="radio3" class="manual-button"></label>
<label for="radio4" class="manual-button"></label>
<label for="radio5" class="manual-button"></label>
<label for="radio6" class="manual-button"></label>
</div>
</div var counter = 1;
setInterval(function()
{document.getElementById('radio' + counter).checked = true;
counter++;
if(counter > 6){
counter = 1;
}
}, 5000);我想在滑块中添加下一个/前一个函数,但是我对编写代码感到困惑,有人想帮忙吗?
发布于 2022-11-15 05:22:19
Please refer to below javascript link and it will work for you 100%.发布于 2022-11-15 05:27:03
像这样检查一下,
<div id="next" onclick="nextClick()"></div>
<div id="previous" onclick="preClick()"></div>
function nextClick(){
document.getElementById('radio' + counter).checked = true;
counter++;
if(counter > 6){
counter = 1;
}
}
function preClick(){
counter = counter - 2;
document.getElementById('radio' + counter).checked = true;
counter++;
if(counter > 6){
counter = 1;
}
}记住,counter变量是一个全局变量。
https://stackoverflow.com/questions/74440881
复制相似问题