gpt4 book ai didi

jQuery : Change options of select tag list automatically

转载 作者:搜寻专家 更新时间:2023-10-31 23:08:54 26 4
gpt4 key购买 nike

我在选择标签中有两个下拉列表项

第一个选择标签有年份列表第二个选择标签有月份列表

<SELECT id="year" onchange="showData();">
<OPTION VALUE="2012">2012
<OPTION VALUE="2011">2011
<OPTION VALUE="2010">2010
<OPTION VALUE="2009">2009
<OPTION VALUE="2008">2008
</SELECT>

<SELECT id="month" onchange="showData();">
<OPTION VALUE="jan">jan
<OPTION VALUE="feb">feb
<OPTION VALUE="mar">mar
.
.
<OPTION VALUE="dec">dec
</SELECT>

所以我怎么能自动更改 5 秒后的月份和一年的 60 秒

我的 jquery 是什么

function changeMonthYear() {    
//what to code here to change option of select tag
//automatically after some time
//say 5 sec per month & after 60 sec year will be changed
showData();
}

showData() {
//some logic will show data for selected year & month
}

如何解决

最佳答案

尝试一下

function changeYear() {

$('option:selected', '#year').removeAttr('selected').next('option').attr(
'selected', 'selected'); //your id of select tag is 'year'

showData();

}

function changeYearMonth() {

$('option:selected', '#month').removeAttr('selected').next('option')
.attr('selected', 'selected'); //your id of select tag is 'month'

showData();

}

setInterval(changeYear, 60000);
setInterval(changeYearMonth, 5000);

showData(){

//some logic will show data for selected year & month

}

关于jQuery : Change options of select tag list automatically,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12620539/

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