gpt4 book ai didi

javascript - 如何每 30 秒自动更改一次下拉选项

转载 作者:行者123 更新时间:2023-12-03 05:33:18 29 4
gpt4 key购买 nike

我已经完成了上一个和下一个的下拉菜单。我想知道如何每 n 秒自动更改下拉选项值。 https://jsfiddle.net/wmwayysz/

 <script  
src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js">
</script>
<button type="button" id="prev">Previous</button>
<select id="selectBox" onchange="currentSlide(value);" class="selectpicker">
<option value="1" class="options">Electronics</option>
<option value="2" class="options">Clothing</option>
<option value="3" class="options">Health</option>
<option value="4" class="options">Food</option>
<option value="5" class="options">Travel</option>
<option value="6" class="options">Mobiles</option>
<option value="7" class="options">Grocery</option>
<option value="8" class="options">Recharge</option>
<option value="9" class="options">Furniture</option>


下一页

 $.fn.loopNext = function(selector) {
var selector = selector || '';
return this.next(selector).length ? this.next(selector) :
this.siblings(selector).addBack(selector).first();
}
$.fn.loopPrev = function(selector) {
var selector = selector || '';
return this.prev(selector).length ? this.prev(selector) :
this.siblings(selector).addBack(selector).last();
}
$("#next").click(function() {
$('#selectBox > option:selected')
.removeAttr('selected')
.loopNext('option')
.prop('selected', 'selected');
});

$("#prev").click(function() {
$('#selectBox > option:selected')
.removeAttr('selected')
.loopPrev('option')
.prop('selected', 'selected');
});

function currentSlide(selectionValue) {
console.log(selectionValue);
}

最佳答案

试试这个

setInterval(function() {
$('#next').trigger('click');
}, 30000)

关于javascript - 如何每 30 秒自动更改一次下拉选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40839619/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com