Three levels of interaction,

Source: Internet
Author: User

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)})

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.