يتضمن حكم الشهر الكثير من شروط الحكم ، إذا كان آخر سيقلل من الأداء بشكل كبير. يوصى باستخدام بناء جملة التبديل
الرمز كما يلي:
نسخة الكود كما يلي:
getDays: وظيفة (سنة ، شهر) {
// var aday = [31،28 | 29،31،30،31،30،31،31،31،30،30،31] ؛
// معالجة بيانات يوم فبراير
var fedDays = Year ٪ 4 == 0؟ 29: 28 ،
returndays = '' ؛
var month = month <10؟ month = '0'+month: month.toString () ؛
التبديل (شهر) {
حالة "01":
حالة "03":
حالة "05":
حالة "07":
القضية '08':
القضية "10":
القضية '12': returndays = 31 ؛ استراحة ؛
حالة "04":
حالة "06":
حالة "09":
القضية '11': returndays = 30 ؛ استراحة ؛
القضية '02': returndays = fedDays ؛ break ؛
}
إرجاع أيام العائد ؛
}
رمز المصدر الكامل:
نسخة الكود كما يلي:
/* المؤلف: Laoguoyong
---------------------------------
ربط ثلاثة مستويات للتواريخ ، اختيار المدى
---------------------------------
المعلمة
* [سلسلة] الأهداف: '#سنة ،#الشهر ،#اليوم' ؛ معرف العام والشهر واليوم
* [سلسلة] المدى: '2013-02-03،2019-09-21' ؛ النطاق ، التنسيق الصحيح هو xxxx-xx-xx
--- لحفظ الرمز ، يرجى تمرير المعلمة النطاق الصحيح
---- عرض خطأ:
(1) المدى: "2013-02-03،2019-9-21" خاطئ ، انتبه إلى تنسيق التاريخ
(2) النطاق: "2013-02-03" خاطئ ، يرجى إدخال قيمة النطاق الكامل
(3) المدى: '2013-02-03،2016-02-30' هذا خطأ ، لا يوجد 30 يومًا في فبراير
(3) النطاق: "2013-02-03،2011-02-30" خطأ ، النطاق غير صحيح
*
*/
وظيفة gysetdate (OPT) {
// Elem
VAR الأهداف = opt.targets.split ('،') ؛
this.eyear = this.getId (الأهداف [0] .slice (1)) ؛
this.emonth = this.getID (الأهداف [1] .slice (1)) ؛
this.eday = this.getID (الأهداف [2] .slice (1)) ؛
if (! this.eyear ||! this.emonth ||! this.eday) return ؛
// قيمة المدى
var r = opt.range.indexof ('،') ،
ASTARTS = OPT.RANGE.SLICE (0 ، R) .SPLIT ('-') ، // تحويل إلى: ['2013' ، '05' ، '20']
arends = opt.range.slice (r+1 ، opt.range.length) .split ('-') ؛ // تحويل إلى: ['2018' ، '08' ، '20']
// نوع الرقم
this.startyear = parseint (Astarts [0] ، 10) ؛
this.startmonth = parseint (Astarts [1] ، 10) ؛
this.startDay = parseint (Astarts [2] ، 10) ؛
this.endyear = parseint (enends [0] ، 10) ؛
this.endmonth = parseint (ends [1] ، 10) ؛
this.endday = parseint (ends [2] ، 10) ؛
this.init () ؛
}
gysetdate.prototype = {
init: function () {
var _ that = this ؛
// تاريخ التهيئة
this.setyears ({'start': this.startyear ، 'end': this.endyear}) ؛
this.setMonths ({'start': this.startmonth}) ؛
this.setDays ({'year': this.startyear ، 'month': this.startmonth ، 'start': this.startday}) ؛
// اختيار السنة
this.eyear.onchange = function () {
var year = parseint (this.value) ؛
التبديل (صحيح) {
الحالة (السنة == _ that.startyear): {
_That.setMonths ({'start': _ that.startmonth}) ؛
-
}؛استراحة؛
الحالة (السنة == _ that.endyear): {
_That.setMonths ({'start': 1 ، 'end': _ that.endmonth}) ؛
if (_that.endmonth> 1) {
_That.SetDays ({'year': _ that.endyear ، 'month': 1 ، 'start': 1}) ؛
}آخر{
-
}
}؛استراحة؛
تقصير:{
_ that.setMonths ({'start': 1}) ؛
_ that.setDays ({'start': 1 ، 'year': year ، 'month': 1}) ؛
}
}
}
// الاختيار الشهري
this.emonth.onchange = function () {
var year = parseint (_that.eyear.options [_That.eyear.SelectedIndex] .value) ،
الشهر = parseint (this.value) ؛
التبديل (صحيح) {
الحالة (السنة == _ that.endyear && month == _ that.endmonth): {
_That.SetDays ({'start': 1 ، 'year': year ، 'month': month ، 'end': _ that.endday}) ؛
}؛استراحة؛
الحالة (السنة == _ that.startyear && month == _ that.startmonth): {
-
}؛استراحة؛
تقصير:{
-
}
}
}
} ،
/*محدد السنة ، الشهر ، اليوم
---------------------------------
جميع قيم المعلمات من نوع الرقم
*/
// المعلمات {'start': xx ، 'end': xxx}
setyears: function (OPT) {
this.eyear.innerhtml = '' ؛
لـ (var n = opt.start ؛ n <= opt.end ؛ n ++) {
this.eyear.add (خيار جديد (n ، n)) ؛
}
} ،
// المعلمات {'start': xx ، 'end': xxx}
// المعلمة "نهاية" اختيارية ، وتجاهلها ، وتبدأ حتى ديسمبر
setMonths: Function (OPT) {
this.emonth.innerhtml = '' ؛
var أشهر = opt.end || 12 ؛
لـ (var n = opt.start ؛ n <= الشهور ؛ n ++) {
إذا (n <10) n = '0'+n ؛
this.emonth.add (خيار جديد (n ، n)) ؛
}
} ،
// المعلمات {'start': xx ، 'year': xxx ، 'month': xx ، 'star': xx ، 'end': xxx}
// المعلمة "نهاية" اختيارية ، وتجاهلها ، وتبدأ حتى نهاية هذا الشهر (تم الحكم عليها على أساس الشهر)
setDays: Function (OPT) {
this.eday.innerhtml = '' ؛
var days = opt.end || this.getDays (opt.year ، opt.month) ؛
لـ (var n = opt.start ؛ n <= days ؛ n ++) {
إذا (n <10) n = '0'+n ؛
this.eday.add (خيار جديد (n ، n)) ؛
}
} ،
/* وفقًا للسنة والشهر ، إرجاع العدد الصحيح من الأيام ، مثل 2016-2 ، العائد هو 29 يومًا (سنة التشغيل)
-------------------------------------------------------------
جميع قيم المعلمات من نوع الرقم
*/
getDays: وظيفة (سنة ، شهر) {
// var aday = [31،28 | 29،31،30،31،30،31،31،31،30،30،31] ؛
// معالجة بيانات يوم فبراير
var fedDays = Year ٪ 4 == 0؟ 29: 28 ،
returndays = '' ؛
var month = month <10؟ month = '0'+month: month.toString () ؛
التبديل (شهر) {
حالة "01":
حالة "03":
حالة "05":
حالة "07":
القضية '08':
القضية "10":
القضية '12': returndays = 31 ؛ استراحة ؛
حالة "04":
حالة "06":
حالة "09":
القضية '11': returndays = 30 ؛ استراحة ؛
القضية '02': returndays = fedDays ؛ break ؛
}
إرجاع أيام العائد ؛
} ،
/* وظيفة المساعد الأداة
---------------------------------
*/
getID: وظيفة (معرف) {
return document.getElementById (id) ؛
}
}
صورة عرض التأثير:
التأثير جيد جدا. الأصدقاء ، يرجى تجميله بنفسك واستخدامه في مشروعك.