jquery 联动 年月日

<html xmlns="http://www.w3.org/1999/xhtml">  
<head>  
    <title>JQuery实例 - 生成年月日</title>  
    <meta http-equiv="content-type" content="text/html; charset=gbk">  
    <script type="text/javascript" src="jquery.js"></script>  
    <script type="text/javascript">   
        $(function () {  
            var $day = $("#day"),  
              $month = $("#month"),  
              $year = $("#year");  
  
            <!--初始化年-->  
            var dDate = new Date(),  
              dCurYear = dDate.getFullYear(),  
              str = "";  
            for (var i = dCurYear - 70; i < dCurYear + 70; i++) {  
                if (i == dCurYear) {  
                    str = "<option value=" + i + " selected=true>" + i + "</option>";  
                } else {  
                    str = "<option value=" + i + ">" + i + "</option>";  
                }  
                $year.append(str);  
            }  
  
            <!--初始化月-->  
            for (var i = 1; i <= 12; i++) {  
  
                if (i == (dDate.getMonth() + 1)) {  
                    str = "<option value=" + i + " selected=true>" + i + "</option>";  
                } else {  
                    str = "<option value=" + i + ">" + i + "</option>";  
                }  
                $month.append(str);  
            }  
            <!--调用函数出始化日-->  
            TUpdateCal($year.val(), $month.val());  
            $("#year,#month").bind("change", function(){  
                TUpdateCal($year.val(),$month.val());  
            });  
        });  
  
        <!--依据年月获取当月最大天数-->  
        function TGetDaysInMonth(iMonth, iYear) {  
            var dPrevDate = new Date(iYear, iMonth, 0);  
            return dPrevDate.getDate();  
        }  
  
        function TUpdateCal(iYear, iMonth) {  
            var dDate = new Date(),  
                daysInMonth = TGetDaysInMonth(iMonth, iYear),  
                str = "";  
  
            $("#day").empty();  
  
            for (var d = 1; d <= parseInt(daysInMonth); d++) {  
  
                if (d == dDate.getDate()) {  
                    str = "<option value=" + d + " selected=true>" + d + "</option>";  
                } else {  
                    str = "<option value=" + d + ">" + d + "</option>";  
                }  
                $("#day").append(str);  
            }  
        }  
  
    </script>  
  
</head>  
<body>  
<form name="ymd">  
    <select id="year"></select>年  
    <select id="month"></select>月  
    <select id="day"></select>日  
</form>  
</body>  
</html>

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值