Home >Web Front-end >JS Tutorial >Implement a javascript code for year, month and quarter linkage SELECT_form special effects

Implement a javascript code for year, month and quarter linkage SELECT_form special effects

WBOY
WBOYOriginal
2016-05-16 19:11:311067browse

[Ctrl A select all Note: If you need to introduce external Js, you need to refresh to execute
]<script> function GetValue(){ var objlist = document.getElementsByTagName("SELECT"); var tmp = new Array(); var tap = objlist[0].options[objlist[0].selectedIndex].text; strTmp=""; var j = 1; for(var i=1;i<objlist.length;i++){ if(objlist[i].style.display!="none"){ strTmp += objlist[i].options[objlist[i].selectedIndex].text + "-"; j++; } } strTmp = strTmp.substring(0,strTmp.length-1); alert(tap); alert(strTmp); } function hideAll(){ for(i=1;i<5;i++){ var select = document.getElementById("submenu_"+i); while(select.options.length>0){ select.options.remove(0); } select.style.display = "none"; } } function initSelect(index){ var select = document.getElementById("submenu_"+index); var now = new Date(); var currentYear = now.getYear(); var month = now.getMonth(); switch(index){ case 1: for(i=-5;i<=5;i++){ var value = currentYear+i; var item = new Option(value,value); select.options.add(item); } select.selectedIndex = 5; select.style.display = "block"; break; case 2: var semiyears = new Array("上半年","下半年"); for(i=0;i<2;i++){ var item = new Option(semiyears[i],i+1); select.add(item); } select.selectedIndex = Math.floor(month/6); select.style.display = "block"; break; case 3: var quarters = new Array("一季度","二季度","三季度","四季度"); for(i=0;i<4;i++){ var item = new Option(quarters[i],i+1); select.add(item); } select.selectedIndex = Math.floor(month/3); select.style.display = "block"; break; case 4: var months = new Array("一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"); for(i=0;i<12;i++){ var item = new Option(months[i],i+1); select.add(item); } select.selectedIndex = month; select.style.display = "block"; break; default: break; } } function displaySubmenu(command){ hideAll(); if(command != "none"){ var commands = command.split(","); for(l=0;l<commands.length;l++){ initSelect(parseInt(commands[l])); } } } </script>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn