This article mainly introduces the relevant information of the three-level linkage example code of PHP year, month and day. Friends who need it can refer to
Three-level linkage of year, month and day
<input type="text" id="hs"> <input type="button" id="btn" value="提交"> <span id="rent"></span>
The three-level linkage of this year, month and day mainly uses the select tag
var str = "<select id='year'></select> <select id='month'>" + "</select> <select id='day'></select>"; $("#rent").html(str); fullyear(); fullmonth(); fullday(); //当其中一个改变,后面的要跟着改变 $("#year").change(function(){ fullday(); }); $("#month").change(function(){ fullday(); }); function fullyear() { var d = new Date(); var year = d.getFullYear(); str =""; for(var i=year-5;i<year+6;i++) { if(i==year) { str += "<option selected='selected' value='"+i+"'>"+i+"</option>"; } else { str +="<option value='"+i+"'>"+i+"</option>" } } $("#year").html(str); } function fullmonth() { var d = new Date(); var month = d.getMonth()+1; str =""; for(var j=1;j<13;j++) { if(j==month) { str += "<option selected='selected' value='"+j+"'>"+j+"</option>"; } else { str +="<option value='"+j+"'>"+j+"</option>" } } $("#month").html(str); } function fullday() { var d = new Date(); var day = d.getDate(); var year=$("#year").val(); var month=$("#month").val(); var rq=31; str =""; if(month==4|| month==6|| month==9|| month===11) { rq=30; } else if(month==2) { if(year%4==0 && year%100!=0 || year%400==0) { rq=29;//闰年 } else{ rq=28; //不是闰年 } } for(var n=1;n<rq+1;n++) { if(n==day) { str +="<option selected='selected' value='"+n+"'>"+n+"</option>"; } else { str +="<option value='"+n+"'>"+n+"</option>"; } } $("#day").html(str); } //到这里就完成了下拉列表的内容了,下一步要做的是把内容存到表单中
$("#btn").click(function(){ var nian=$("#year").val(); var yue=$("#month").val(); var ri=$("#day").val(); var time=nian+"-"+yue+"-"+ri+""; $("#hs").val(time) })
Related recommendations:
JS simple method to get the current year, month, day, week
jQuery gets the age implementation code based on the birthyear, month, and day
The above is the detailed content of PHP method to realize three-level linkage of year, month and day. For more information, please follow other related articles on the PHP Chinese website!