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 相关文章推荐
Gird事件机制初级读本
Mar 10 Javascript
javaScript 数值型和字符串型之间的转换
Jul 25 Javascript
JavaScript中的DSL元编程介绍
Mar 15 Javascript
基于BootStrap Metronic开发框架经验小结【九】实现Web页面内容的打印预览和保存操作
May 12 Javascript
bootstrap学习笔记之初识bootstrap
Jun 21 Javascript
自己封装的一个原生JS拖动方法(推荐)
Nov 22 Javascript
Javarscript中模块(module)、加载(load)与捆绑(bundle)详解
May 28 Javascript
JS身份证信息验证正则表达式
Jun 12 Javascript
详解webpack分包及异步加载套路
Jun 29 Javascript
vue项目中jsonp跨域获取qq音乐首页推荐问题
May 30 Javascript
Django+Vue跨域环境配置详解
Jul 06 Javascript
浅谈layui分页控件field参数接收对象的问题
Sep 20 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
火影忍者:这才是千手柱间和扉间的真正死因,角都就比较搞笑了!
2020/03/10 日漫
通过php删除xml文档内容的方法
2015/01/23 PHP
php基于Snoopy解析网页html的方法
2015/07/09 PHP
PHP实现登录搜狐广告获取广告联盟数据的方法【附demo源码】
2016/10/14 PHP
详解PHP处理字符串类似indexof的方法函数
2017/06/11 PHP
PHP实现单条sql执行多个数据的insert语句方法
2019/10/11 PHP
jQuery获取当前对象标签名称的方法
2014/02/07 Javascript
node.js中的http.request.end方法使用说明
2014/12/10 Javascript
javascript特效实现——当前时间和倒计时效果的简单实例
2016/07/20 Javascript
JSON 数据格式详解
2017/09/13 Javascript
JS实现获取汉字首字母拼音、全拼音及混拼音的方法
2017/11/14 Javascript
Vue实现动态创建和删除数据的方法
2018/03/17 Javascript
JSONP原理及应用实例详解
2018/09/13 Javascript
VUE引入第三方js包及调用方法讲解
2019/03/01 Javascript
vue中动态select的使用方法示例
2019/10/28 Javascript
微信小程序picker组件两列关联使用方式
2020/10/27 Javascript
[41:08]TNC vs VG 2018国际邀请赛小组赛BO2 第一场 8.16
2018/08/17 DOTA
详解Python中的多线程编程
2015/04/09 Python
python转换字符串为摩尔斯电码的方法
2015/07/06 Python
在centos7中分布式部署pyspider
2017/05/03 Python
Python升级导致yum、pip报错的解决方法
2017/09/06 Python
python控制windows剪贴板,向剪贴板中写入图片的实例
2018/05/31 Python
使用Python实现毫秒级抢单功能
2019/06/06 Python
python 怎样将dataframe中的字符串日期转化为日期的方法
2019/09/26 Python
python系统指定文件的查找只输出目录下所有文件及文件夹
2020/01/19 Python
Python中import导入不同目录的模块方法详解
2020/02/18 Python
移动Web—CSS为Retina屏幕替换更高质量的图片
2012/12/24 HTML / CSS
泰国的头号网上婴儿用品店:Motherhood.co.th
2019/04/09 全球购物
禁止酒驾标语
2014/06/25 职场文书
2014党员学习习主席讲话思想汇报
2014/09/15 职场文书
2015年财政所工作总结
2015/04/25 职场文书
护士年终工作总结不会写?各科护士模板总结
2020/01/02 职场文书
python 命令行传参方法总结
2021/05/25 Python
MySQL系列之七 MySQL存储引擎
2021/07/02 MySQL
MySQL数据库10秒内插入百万条数据的实现
2021/11/01 MySQL
PYTHON使用Matplotlib去实现各种条形图的绘制
2022/03/22 Python