Este artículo comparte el código relevante para JS para implementar la selección de enlaces de fecha, que es adecuada para la selección de cumpleaños, para su referencia. El contenido específico es el siguiente
Lograr el objetivo: tres cuadros de entrada seleccionados de año, mes y día, y una entrada oculta. Obtenga el valor de la entrada a través de JS. Si hay un valor en el formato de fecha, el año, el mes y el día seleccionar es la hora en la entrada. De lo contrario está vacío. El intervalo predeterminado para el año es de 1900 a este año
He usado bootstrap. Consulte las instrucciones relevantes para Bootstrap para la clase
El siguiente es el contenido HTML:
<Div> <label> <select node-type = "birthrucy_year" name = "birthrucy" id = "birthrucy_y"> <option value = ""> </option> </select> <span> año </span> </selabel> <label> <select node-type = "_month "name =" birthind = "birthday_m"> <option value = "> </poption> </elect> <span> mes </span> </selet> <label> <select Node-Type = "Birthrucy_month" name = "birthrucy_d" id = "birthday_d"> <option value = ""> </option> </select> <span> mes </span> </etiquetado> <label> <elect node-type = "birthdle_month" name = "birthind" id = "id =" birthdle "" "option" " value = ""> </option> </select> <span> Day </span> </label> <input type = "Hidden" name = "birth" id = "birth" value = "2016/2/12"> <etiqueta class = 'checkbox-inline-warning hidden' id = "birth_error_info"> <i class = 'fa fa wh-warning'> por favor ingrese el cumpleaños completo </i etiquetador </iTrinfo </ITH/ITTULT </ITH/ETABLE </ITH/ETABLE </I Labor.
Aquí está la implementación de JS:
// Establezca la conversión y obtenga el cumpleaños de var fecha = nueva fecha (); var año = date.getTlyEar (); para (var i = año; i> = 1900; i-) {$ ("#bucouthel_y"). append ("<option value ="+i+"etiqueta ="+i+">"+i+"</opción>"); } $ ('#bucoavlation_y'). Change (function () {var birth_year = $ ('#bucoavlation_y'). val (); if (birth_year! = "") {var birth_month = $ ('#bucoavlation_m'). val (); if (birth_month! = ") {var birth_month = $ ('#birthind birthdle_m'). val (); if (birth! =") ") var birth_month = $ ('#bucley_m'). val (); + ">" + 29 + "</opción>"); } else {$ ("#bucley_m"). html ("<option value = ''> </option>"); $ ('#bucoavlation_m'). Change (function () {var birth_year = $ ('#bucoavlation_y'). val (); var birth_month = this.Value; var birth_day = $ ('#bucoavlation_d'). val (); if (birth_month! = "") {switch (birth_month) {case ": case" 3 ": case" 5 "5" Case "7" "" 8 "" 8 "" "8" "" "", 8 "" "", 8 "" ", 8" "" ", 8" "" ", 8" "" "", 8 "" "", 8 "" "", 8 "" ", 8" "" ", 8" "" ", 8" "" ", 8" "", 8 "" ", 8" "" "". "10": Case "12": if (birth_day == "") {$ ("#bucleating"). Vacío (); "</option>"); "</opción>"); "11": if (birth_day == "") {$ ("#bucley_d"). Append ("<option value = '' '> </option>"); ($ ("#birthrucy_d opción: último"). attr ("valor")) {case "28": $ ("#buclea_d"). append ("<opción valor =" + 29 + ">" + 29 + "</opción>") "31": $ ("#bucoavlation") opción [value = '31 '] "). Remove (); break; default: break;}} break; caso" 2 ": if (birth_day ==" ") {if (birth_year%4 == 0 && birthrucy%100! = 0) || (birth_year%400 == 0)) {para (var i = 1; i <29; i <29) $ ("#bucouthel_d"). append ("<option value ="+i+"etiqueta ="+i+">"+i+"</opción>"); }} else {$ ("#birthdle_d opción [valor = '31 ']"). remove (); opción [valor = '29 '] "). remove ();}} break; default: break;}} checkbirthday ();}); $ ('#bucoavlation '). Change (function () {checkbirthday ();}); $ (' #d '). focus (function () {if ('#birthind birthind birthday_m '). Val () ==" "" "") $ ("#Birthday_D"). b_year = date1.getblyear (); <= 12; 7: Caso 8: Caso 10: Caso 12: for (var i = 1; i <= 31; i ++) {$ ("#bucleal_d"). (var i = 1; i <= 30; i ++) {$ ("#bucley_d"). append ("<option value =" + i + "etiqueta =" + i + ">" + i + "</opción>") i = 1; i <= 29; i ++) {$ ("#bucouthel_d"). append ("<option value ="+i+"etiqueta ="+i+">"+i+"</opción>"); etiqueta = "+i+"> "+i+" </option> ");}} break; default: break;} $ ("#bucoavlation_d "). Buscar (" opción [value = '"+b_day+"'] "). attr (" seleccionado "," seleccionado ");} // verifique que la función completa checkbirthday () {var b_year = $ ('#birthday_y'). b_month = $ ('#bucley_m'). val (); $ ('#birth_error_info'). AddClass ("Hidden");Si aún desea aprender en profundidad, puede hacer clic aquí para aprender y adjuntar dos temas emocionantes a usted: Tutorial de aprendizaje Bootstrap Bootstrap Tutorial práctico
Lo anterior se trata de este artículo, espero que sea útil para el aprendizaje de todos.