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 相关文章推荐
tbody元素支持嵌套的注意方法
Mar 24 Javascript
JavaScript基础篇之变量作用域、传值、传址的简单介绍与实例
Jun 29 Javascript
原生JavaScript实现动态省市县三级联动下拉框菜单实例代码
Feb 03 Javascript
基于JavaScript实现百叶窗动画效果不只单纯flas可以实现
Feb 29 Javascript
javascript加减乘除的简单实例
Jul 12 Javascript
jQuery根据ID、CLASS、等获取对象的实例
Dec 04 Javascript
JS实现随机颜色的3种方法与颜色格式的转化
Jan 05 Javascript
vue语法之拼接字符串的示例代码
Oct 25 Javascript
vue中的scope使用详解
Oct 29 Javascript
如何为你的JS项目添加智能提示与类型检查详解
Mar 12 Javascript
mpvue开发音频类小程序踩坑和建议详解
Mar 12 Javascript
vue.js表单验证插件(vee-validate)的使用教程详解
May 23 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 中的批处理的实现
2007/06/14 PHP
php URL跳转代码 减少外链
2011/06/25 PHP
php判断上传的Excel文件中是否有图片及PHPExcel库认识
2013/01/11 PHP
浅析Mysql 数据回滚错误的解决方法
2013/08/05 PHP
[原创]PHP字符串中插入子字符串方法总结
2016/05/06 PHP
php基于curl主动推送最新内容给百度收录的方法
2016/10/14 PHP
php插入mysql数据返回id的方法
2018/05/31 PHP
PHP实现网站应用微信登录功能详解
2019/04/11 PHP
javascript getElementsByClassName实现代码
2010/10/11 Javascript
JS获取图片实际宽高及根据图片大小进行自适应
2013/08/11 Javascript
javascript实例分享---具有立体效果的图片特效
2014/06/08 Javascript
浅析基于WEB前端页面的页面内容搜索的实现思路
2014/06/10 Javascript
JS组件系列之Bootstrap table表格组件神器【二、父子表和行列调序】
2016/05/10 Javascript
JavaScript程序中的流程控制语句用法总结
2016/05/23 Javascript
artDialog+plupload实现多文件上传
2016/07/19 Javascript
jQuery中delegate()方法的用法详解
2016/10/13 Javascript
详解微信小程序文件下载--视频和图片
2019/04/24 Javascript
ES6中Promise的使用方法实例总结
2020/02/18 Javascript
vue打包通过image-webpack-loader插件对图片压缩优化操作
2020/11/12 Javascript
Python3里的super()和__class__使用介绍
2015/04/23 Python
Python实现文件复制删除
2016/04/19 Python
对Python中实现两个数的值交换的集中方法详解
2019/01/11 Python
selenium+python自动化测试之多窗口切换
2019/01/23 Python
python利用os模块编写文件复制功能——copy()函数用法
2020/07/13 Python
Numpy数组的广播机制的实现
2020/11/03 Python
python中pyqtgraph知识点总结
2021/01/26 Python
python实现学生通讯录管理系统
2021/02/25 Python
文化活动实施方案
2014/03/28 职场文书
给校长的建议书500字
2014/05/15 职场文书
文秘应届生求职信
2014/07/05 职场文书
我是一名护士演讲稿
2014/08/28 职场文书
2014年残联工作总结
2014/11/21 职场文书
外出听课学习心得体会
2016/01/15 职场文书
奖学金申请书(范文)
2019/08/14 职场文书
nginx负载功能+nfs服务器功能解析
2022/02/28 Servers
SQL Server使用T-SQL语句批处理
2022/05/20 SQL Server