Dieser Artikel teilt den entsprechenden Code für JS mit der Implementierung der Datumsverknüpfungsauswahl, die für die Geburtstagsauswahl für Ihre Referenz geeignet ist. Der spezifische Inhalt ist wie folgt
Erreichen Sie das Ziel: Drei Eingangsfelder von Jahr, Monat und Tag und eine versteckte Eingabe. Holen Sie sich den Wert der Eingabe über JS. Wenn das Datumsformat einen Wert gibt, ist das Jahr, der Monat und die Tagesauswahl die Zeit in der Eingabe. Sonst ist es leer. Das Standardintervall für das Jahr ist von 1900 bis in diesem Jahr
Ich habe Bootstrap verwendet. Bitte beachten Sie die entsprechenden Anweisungen für Bootstrap für den Unterricht
Das Folgende ist der HTML -Inhalt:
<Div> <label> <select node-type = "birthday_year" name = "birthday_y" id = "birthday_y"> <option value = ""> </option> </select> <span> Jahr </span> </label> <label> <select node-type = "birthday_month" name = "birthals_m" id = " </select> <span> Monat </span> </label> <label> <select node-type = "birthday_month" name = "birthday_d" id = "birthday_d"> <option value = ""> </option> </select> <span> Monat </span> </label> <label> < value = ""> </option> </select> <span> Tag </span> </label> <Eingabe type = "Hidden" name = "birth" id = "birth" value = "2016/2/12"> <label class = 'Checkbox-Inline-Textwarning Hidden' id = "birth_error_info"> <i class = 'fa-fa-warning'
Hier ist die Implementierung von JS:
// Setzen Sie die Konvertierung und erhalten Sie den Geburtstag von var date = new Date (); var yeal = Datum.GetingFoyear (); für (var i = Jahr; i> = 1900; i-) {$ ("#birthday_y"). append ("<option value ="+i+"label ="+i+">"+i+"</option>"); } $ ('#birthday_y'). Change (function () {var birth_year = $ ('#birthday_y'). val (); if (birg.year! var birth_month = $ ('#birthday_m'). val (); + ">" + 29 + "</option>"); } else {$ ("#birthday_m"). $ ('#birthday_m'). Change (function () {var birth_year = $ ('#birthday_y'). val (); var birth_month = this.value; var birth_day = $ ('#birthday_d'). val (); if (birg month! "10": case "12": if (birth_day == "") {$ ("#birthday_d"). Leer (); "</option>"); "Option>"); "11" ($ ("#birthday_d Option: letztes"). Attr ("Wert") {case "28": $ ("#birthday_d"). Anhang ("<Option Value =" + 29 + ">" + 29 + "</option>"); "31": $ ("#birthday_d") Option [value = '31 '] "). REMET (); Break; Standard: Break;}} Break; Fall" 2 ": if (birth_day ==") {if (birg (birth_year "year%4 == 0 && birthday_year 100! = 0) | | $ ("#birthday_d"). append ("<option value ="+i+"label ="+i+">"+i+"</option>");}} else {für (var i = 1; i <= 28; }} else {$ ("#birthday_d Option [value = '31 ']"). REMET (); Option [value = '29 '] "). remove ();}} break; Standard: break;}} checkbirtday ();}); $ ("#birthday_d") B_YEAR = DATE1.GEGEBOTE (); i <= 12; 5: Fall 7: Fall 8: Fall 10: Fall 12: für (var i = 1; i <= 31; i ++) {$ ("#birthday_d"). Anhang ("<Option Value =" + i + "Label =" + i + " + i +" </option> "); > </option> "); für (var i = 1; i <= 30; i ++) {$ ("#birthday_d "). append (" <option value = " + i +" label = " + i +"> " + i +" </option> ");} break; case 2: if (b_year%4 == 0 && id. für (var i = 1; i <= 29; i ++) {$ ("#birthday_d"). append ("<option value ="+i+"label ="+i+">"+i+"</option>"); label="+i+">"+i+"</option>"); } } break; default :break; } $("#birthday_d").find("option[value='"+b_day+"']").attr("selected","selected"); } // Verify that the full function checkBirthday(){ var b_year= $('#birthday_y').val(); var b_month = $ ('#birthday_m'). val (); $ ('#birth_error_info').Wenn Sie weiterhin ausführlich lernen möchten, können Sie hier klicken, um Ihnen zu lernen und Ihnen zwei aufregende Themen anzuhängen: Bootstrap -Lern -Tutorial Bootstrap Practical Tutorial
Das Obige dreht sich alles um diesen Artikel, ich hoffe, es wird für das Lernen aller hilfreich sein.