Three levels of interaction,
<Input type = "text" id = "hs"> <input type = "button" id = "btn" value = "Submit"> <span id = "rent"> </span>
The select tag is used for the Three-Level Association of the year, month, and day.
Var str = "<select id = 'Year'> </select> & nbsp; <select id = 'month'>" + "</select> & nbsp; & nbsp; <select id = 'day'> </select> "; $ (" # rent "2.16.html (str); fullyear (); fullmonth (); fullday (); // when one of the changes, the subsequent changes will follow $ ("# 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" 2.16.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 + "</opt Ion> "}}$ (" # month "2.16.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 & amp; year % 100! = 0 | year % 400 = 0) {rq = 29; // leap year} else {rq = 28; // not a leap year} 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" detail .html (str);} // the drop-down list is completed here. The next step is to save the content to the form.
$("#btn").click(function(){ var nian=$("#year").val(); var yue=$("#month").val(); var ri=$("#day").val();var time=nian+"-"+yue+"-"+ri+""; $("#hs").val(time)})