js日期、星座的级联显示代码


Posted in Javascript onJanuary 23, 2014

js 代码

    function birthdayOnchange(obj) {
        var year = $("<%= DDL_Year.ClientID%>").value;
        if (year == "year")
            return;
        else
            year = parseInt(year, 10);

        var month = $("<%=DDL_Month.ClientID%>").value;
        if (month == "month")
            return;
        else
            month = parseInt(month, 10);
        var day = $("<%=DDL_Day.ClientID%>").value;
        var wholeday = getDays(year, month);
        if (1) {
            var options = $("<%=DDL_Day.ClientID%>").options;
            for (var i = 1; i <= wholeday; i++) {
                var j = i.toString();
                j = j.length == 1 ? "0" + j : j;
                options.length = i + 1;
                options[i].value = j;
                options[i].text = j;
                if (day <= wholeday && i == day) {
                    options[i].selected = true;
                }
            }
        }
    }
 function getDays(year, month) {
        var dayarr = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
        if (month == 2) {
            if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0 || year < 1900)
                return 29;
            else
                return dayarr[month - 1];
        }
        else {
            return dayarr[month - 1];
        }
    }
    function adjustAstro() {
        var v_astro = getAstro($("<%=DDL_Month.ClientID%>").value, $("<%=DDL_Day.ClientID%>").value);
        $("<%=astro.ClientID %>").options[0].text = v_astro;
    }
    function getAstro(v_month, v_day) {
        v_month = parseInt(v_month, 10)
        v_day = parseInt(v_day, 10);
        if ((v_month == 12 && v_day >= 22)
  || (v_month == 1 && v_day <= 20)) {
            return "魔羯座";
        }
        else if ((v_month == 1 && v_day >= 21)
  || (v_month == 2 && v_day <= 19)) {
            return "水瓶座";
        }
        else if ((v_month == 2 && v_day >= 20)
  || (v_month == 3 && v_day <= 20)) {
            return "双鱼座";
        }
        else if ((v_month == 3 && v_day >= 21)
  || (v_month == 4 && v_day <= 20)) {
            return "白羊座";
        }
        else if ((v_month == 4 && v_day >= 21)
  || (v_month == 5 && v_day <= 21)) {
            return "金牛座";
        }
        else if ((v_month == 5 && v_day >= 22)
  || (v_month == 6 && v_day <= 21)) {
            return "双子座";
        }
        else if ((v_month == 6 && v_day >= 22)
  || (v_month == 7 && v_day <= 22)) {
            return "巨蟹座";
        }
        else if ((v_month == 7 && v_day >= 23)
  || (v_month == 8 && v_day <= 23)) {
            return "狮子座";
        }
        else if ((v_month == 8 && v_day >= 24)
  || (v_month == 9 && v_day <= 23)) {
            return "处女座";
        }
        else if ((v_month == 9 && v_day >= 24)
  || (v_month == 10 && v_day <= 23)) {
            return "天秤座";
        }
        else if ((v_month == 10 && v_day >= 24)
  || (v_month == 11 && v_day <= 22)) {
            return "天蝎座";
        }
        else if ((v_month == 11 && v_day >= 23)
  || (v_month == 12 && v_day <= 21)) {
            return "射手座";
        }
        return "";
    }

html
                <DIV>出生日期:</DIV>
                <DIV>
                    <asp:DropDownList ID="DDL_Year" runat="server"  onchange="birthdayOnchange(this);"></asp:DropDownList> 年 
                    <asp:DropDownList ID="DDL_Month" runat="server"  onchange="birthdayOnchange(this);adjustAstro();"></asp:DropDownList> 月 
                    <asp:DropDownList ID="DDL_Day" runat="server" onchange="adjustAstro();"></asp:DropDownList> 日 
                </DIV>
                <DIV>星座:</DIV>
                <DIV>
                    <SELECT id=astro disabled name=astro runat="server"> 
                        <OPTION selected>处女座</OPTION>
                    </SELECT>
                </DIV>
Javascript 相关文章推荐
js使用函数绑定技术改变事件处理程序的作用域
Dec 26 Javascript
影响jQuery使用的14个方面
Sep 01 Javascript
javascript获取select值的方法分析
Jul 02 Javascript
jquery特效 点击展示与隐藏全文
Dec 09 Javascript
js判断手机浏览器操作系统和微信浏览器的方法
Apr 30 Javascript
javascript三种代码注释方法
Jun 02 Javascript
基于Bootstrap漂亮简洁的CSS3价格表(附源码下载)
Feb 28 Javascript
详解如何在 vue 项目里正确地引用 jquery 和 jquery-ui的插件
Jun 01 jQuery
详解用vue.js和laravel实现微信授权登陆
Jun 23 Javascript
Vuex mutitons和actions初使用详解
Mar 04 Javascript
JS实现超级好看的鼠标小尾巴特效
Dec 01 Javascript
8个非常实用的Vue自定义指令
Dec 15 Vue.js
js根据日期判断星座的示例代码
Jan 23 #Javascript
jQuery中Dom的基本操作小结
Jan 23 #Javascript
利用js正则表达式验证手机号,email地址,邮政编码
Jan 23 #Javascript
js验证电话号码与手机支持+86的正则表达式
Jan 23 #Javascript
Jquery 过滤器(first,last,not,even,odd)的使用
Jan 22 #Javascript
Jquery遍历节点的方法小集
Jan 22 #Javascript
Jquery如何实现点击时高亮显示代码
Jan 22 #Javascript
You might like
PHP开发中常用的8个小技巧
2008/08/27 PHP
查找mysql字段中固定字符串并替换的几个方法
2012/09/23 PHP
探讨PHP调用时间格式的参数详解
2013/06/06 PHP
解析MySql与Java的时间类型
2013/06/22 PHP
php使用NumberFormatter格式化货币的方法
2015/03/21 PHP
php在windows环境下获得cpu内存实时使用率(推荐)
2018/02/08 PHP
thinkPHP5框架auth权限控制类与用法示例
2018/06/12 PHP
xmlHTTP实例
2006/10/24 Javascript
一个很简单的jquery+xml+ajax的无刷新树结构(无css,后台是c#)
2010/06/02 Javascript
JavaScript对象、属性、事件手册集合方便查询
2010/07/04 Javascript
利用js实现遮罩以及弹出可移动登录窗口
2013/07/08 Javascript
jquery 漂亮的删除确认和提交无刷新删除示例
2013/11/13 Javascript
JS对img标签进行优化使用onerror显示默认图像
2014/04/24 Javascript
jQuery实现的产品自动360度旋转展示特效源码分享
2015/08/21 Javascript
JavaScript与jQuery实现的闪烁输入效果
2016/02/18 Javascript
Active控件问题小结(附解决办法)
2016/06/09 Javascript
基于jQuery实现页面搜索功能
2020/03/26 Javascript
JavaScript 中 apply 、call 的详解
2017/03/21 Javascript
jQuery实现全选、反选和不选功能
2017/08/16 jQuery
微信小程序使用audio组件播放音乐功能示例【附源码下载】
2017/12/08 Javascript
webpack里使用jquery.mCustomScrollbar插件的方法
2018/05/30 jQuery
详解js中的原型,原型对象,原型链
2020/07/16 Javascript
JavaScript实现浏览器网页自动滚动并点击的示例代码
2020/12/05 Javascript
Python yield与实现方法代码分析
2018/02/06 Python
win10下python3.5.2和tensorflow安装环境搭建教程
2018/09/19 Python
python使用列表的最佳方案
2020/08/12 Python
日本航空官方网站:JAL
2019/06/19 全球购物
一套英文Java笔试题面试题
2016/04/21 面试题
仓库班组长岗位职责
2013/12/12 职场文书
高级编程求职信模板
2014/02/16 职场文书
运动会铅球比赛加油稿
2014/09/26 职场文书
党员反对四风思想汇报范文
2014/10/25 职场文书
学校党风廉政建设调研报告
2015/01/01 职场文书
法律意见书范文
2015/05/20 职场文书
幼儿园教师暑期培训心得体会
2016/01/09 职场文书
新手必备Python开发环境搭建教程
2021/05/28 Python