Dieser Artikel beschreibt die Methode, um das Start- und Enddatum von JS zu erhalten und zu überprüfen. Teilen Sie es für Ihre Referenz wie folgt weiter:
Funktion validation () {var startDate = document.getElementById ("start_tenancydate_s"). valy; var enddate = document.getElementById ("end_tenancyDate_s"). value; var dateent = datediff (enddate, startdate); if (startdate == ") {{alert (" Alert ("Alert ("; false;} if (enddate == "") {alert ("Bitte wählen Sie das Enddatum aus!"); return false;} if (datesent> 365) {alert ("Der ausgewählte Datumsunterschied überschreitet den Maximalwert von 1 Jahr!"); true;}} // nennen Sie diese Methode (Hauptmethode) Funktion datiff (Datum1, Datum2) {var type1 = typeof Datum1, Typ2 = TypeOf Datum2; if (type1 == 'String') Datum1 = StringTotime (Datum1); sonst if (Datum1.getTime) Datum1 = Datum1.getTime (); if (type2 == 'String') Datum2 = StringTotime (Datum2); sonst if (Datum2.GetTime) Datum2 = Date2.getTime (); return (Datum1 - Datum2)/(1000 * 60 * 60 * 24); // Außer 1000 ist Millisekunden, es wird keine Sekunde hinzugefügt} // Die Methode, die zum Konvertieren einer StringTotime (String) {var f = String.Split ('', 2) erforderlich ist; var d = (f [0]? f [0]: '') .split ('-', 3); var t = (f [1]? f [1]: '') .Split (':', 3); return (neues Datum (ParseInt (d [0], 10) || null, (parseInt (d [1], 10) || 1) -1, parseInt (d [2], 10) || null, parseInt (t [0], 10) || null, parseInt (t [1], 10) || | |For more information about JavaScript related content, please check out the topics of this site: "Summary of JavaScript Time and Date Operation Skills", "Summary of JavaScript Switching Effects and Skills", "Summary of JavaScript Search Algorithm Skills", "Summary of JavaScript Animation Special Effects and Skills", "Summary of JavaScript Errors and Debugging Skills", "Summary of JavaScript Data Structures and Algorithm Fähigkeiten "," Zusammenfassung des JavaScript -Traversalalgorithmus und der Fähigkeiten "und" Zusammenfassung der Verwendung von JavaScript Mathematical Operation Nutzung ""
Ich hoffe, dieser Artikel wird für JavaScript -Programme aller hilfreich sein.