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 相关文章推荐
Javascript中的Split使用方法与技巧
Mar 09 Javascript
jquery ajax提交整个表单元素的快捷办法
Mar 27 Javascript
返回页面顶部top按钮通过锚点实现(自写)
Aug 30 Javascript
js和php如何获取当前url的内容
Sep 22 Javascript
JS获取节点的兄弟,父级,子级元素的方法
Jan 09 Javascript
JS实现静止元素自动移动示例
Apr 14 Javascript
JQuery选中checkbox方法代码实例(全选、反选、全不选)
Apr 27 Javascript
javascript html实现网页版日历代码
Mar 08 Javascript
JavaScript禁止复制与粘贴的实现代码
May 16 Javascript
JavaScript数组复制详解
Feb 02 Javascript
React Hooks的深入理解与使用
Nov 12 Javascript
vue中beforeRouteLeave实现页面回退不刷新的示例代码
Nov 01 Javascript
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 Notice: Undefined index 错误提示解决方法
2010/08/29 PHP
浅谈COOKIE和SESSION区别
2015/07/19 PHP
深入讲解PHP的Yii框架中的属性(Property)
2016/03/18 PHP
php定期拉取数据对比方法实例
2019/09/22 PHP
JS URL传中文参数引发的乱码问题
2009/09/02 Javascript
JQUBAR1.1 jQuery 柱状图插件发布
2010/11/28 Javascript
jQuery 顶部导航跟随滚动条滚动固定浮动在顶部
2014/06/06 Javascript
node.js中的fs.readlinkSync方法使用说明
2014/12/17 Javascript
jQuery中append()方法用法实例
2015/01/08 Javascript
JS选取DOM元素的简单方法
2016/07/08 Javascript
AngularJS 表达式详细讲解及实例代码
2016/07/26 Javascript
详解vue mint-ui源码解析之loadmore组件
2017/10/11 Javascript
ES6下子组件调用父组件的方法(推荐)
2018/02/23 Javascript
在Vue methods中调用filters里的过滤器实例
2018/08/30 Javascript
vue中,在本地缓存中读写数据的方法
2018/09/21 Javascript
[47:45]Liquid vs OG 2018国际邀请赛小组赛BO2 第二场 8.16
2018/08/17 DOTA
python subprocess 杀掉全部派生的子进程方法
2017/01/16 Python
Pycharm学习教程(6) Pycharm作为Vim编辑器使用
2017/05/03 Python
python2.7+selenium2实现淘宝滑块自动认证功能
2018/02/24 Python
pygame游戏之旅 如何制作游戏障碍
2018/11/20 Python
django的settings中设置中文支持的实现
2019/04/28 Python
Python占用的内存优化教程
2019/07/28 Python
python实现倒计时小工具
2019/07/29 Python
Python读取VOC中的xml目标框实例
2020/03/10 Python
python+selenium 脚本实现每天自动登记的思路详解
2020/03/11 Python
联想新加坡官方网站:Lenovo Singapore
2017/10/24 全球购物
全球独特生活方式产品和礼品购物网站:AHAlife
2018/09/18 全球购物
英国婚礼商城:Wedding Mall
2019/11/02 全球购物
兰蔻法国官方网站:Lancôme法国
2020/02/22 全球购物
如果NULL和0作为空指针常数是等价的,那我到底该用哪一个
2014/09/16 面试题
跟单文员岗位职责
2014/01/03 职场文书
体育教师求职信
2014/05/24 职场文书
硕士生找工作求职信
2014/07/05 职场文书
代办出身证明书
2014/10/21 职场文书
物业客服专员岗位职责
2015/04/07 职场文书
小学教师教育随笔
2015/08/14 职场文书