JavaScript drop-down list box, the content is the current year and the previous 50 years, and the default selection is the current year
The code copy is as follows:
<script language="javascript" type="text/javascript">
window.onload=function(){
//Set the selection of year
var myDate= new Date();
var startYear=myDate.getFullYear()-50;//Start year
var endYear=myDate.getFullYear()+50;//End year
var obj=document.getElementById('myYear')
for (var i=startYear;i<=endYear;i++)
{
obj.options.add(new Option(i,i));
}
obj.options[obj.options.length-51].selected=1;
}
</script>
<select id="myYear"></select>