HTML三级联动日期,日历三级联动.html

Document

(function($) {

$.fn.birthday = function(options) {

var opts = $.extend({}, $.fn.birthday.defaults, options); //整合参数

var $year = $(this).children("select[name=" + opts.year + "]");

var $month = $(this).children("select[name=" + opts.month + "]");

var $day = $(this).children("select[name=" + opts.day + "]");

MonHead = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

return this.each(function() {

var y = new Date().getFullYear();

var con = "";

//添加年份

for (i = y; i <= parseInt(y+1); i++) {

con += "" + i + "年" + "";

}

$year.append(con);

var m = new Date().getMonth()+1;

con1 = "";

con2 = "";

con3 = "";

//添加月份

for (i = m; i <=12; i++) {

con1 += "" + i + "月" + "";

}

for (i = 1; i

con2 += "" + i + "月" + "";

}

for (i = 1; i <12; i++) {

con3 += "" + i + "月" + "";

}

con = con1 +con2;

$month.append(con);

$('.year').change(function(){

if($(this).attr('data-current-year') == $(this).val()){

console.log(1)

$month.append(con3);

}

});

con = "";

//添加日期

var n = MonHead[0]; //默认显示第一月

var d = new Date().getDate();

for (i = d; i <= n; i++) {

con += "" + i + "日" + "";

}

$day.append(con);

$.fn.birthday.change($(this));

console.log(y,m,d,$year[name='']);

});

};

$.fn.birthday.change = function(obj) {

obj.children("select[name=" + $.fn.birthday.defaults.year + "],select[name=" + $.fn.birthday.defaults.month + "]").change(function() {

var $year = obj.children("select[name=" + $.fn.birthday.defaults.year + "]");

var $month = obj.children("select[name=" + $.fn.birthday.defaults.month + "]");

var $day = obj.children("select[name=" + $.fn.birthday.defaults.day + "]");

$day.empty();

var selectedYear = $year.find("option:selected").val();

var selectedMonth = $month.find("option:selected").val();

if (selectedMonth == 2 && $.fn.birthday.IsRunYear(selectedYear)) { //如果是闰年

var c = "";

for (var i = 1; i <= 29; i++) {

c += "" + i + "日" + "";

}

$day.append(c);

} else { //如果不是闰年也没选2月份

var c = "";

for (var i = 1; i <= MonHead[selectedMonth - 1]; i++) {

c += "" + i + "日" + "";

}

$day.append(c);

}

});

};

$.fn.birthday.IsRunYear = function(selectedYear) {

return (0 == selectedYear % 4 && (selectedYear % 100 != 0 || selectedYear % 400 == 0));

};

$.fn.birthday.defaults = {

year: "year",

month: "month",

day: "day"

};

})(jQuery);

$("#birthday_container").birthday();

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值