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与flash交互通信基础教程
Aug 07 Javascript
使用jQuery实现dropdownlist的联动效果(sharepoint 2007)
Mar 30 Javascript
利用JavaScript检测CPU使用率自己写的
Mar 22 Javascript
jQuery实现按钮只点击一次后就取消点击事件绑定的方法
Jun 26 Javascript
jquery Easyui快速开发总结
Aug 20 Javascript
AngularJs 弹出模态框(model)
Apr 07 Javascript
EasyUI在表单提交之前进行验证的实例代码
Jun 24 Javascript
ajax级联菜单实现方法实例分析
Nov 28 Javascript
Vue+webpack+Element 兼容问题总结(小结)
Aug 16 Javascript
记一次vue-webpack项目优化实践详解
Feb 17 Javascript
使用jquery的cookie实现登录页记住用户名和密码的方法
Mar 13 jQuery
Vue打包部署到Nginx时,css样式不生效的解决方式
Aug 03 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
中国第一家无线电行
2021/03/01 无线电
php图片处理:加水印、缩略图的实现(自定义函数:watermark、thumbnail)
2010/12/02 PHP
深入PHP empty(),isset(),is_null()的实例测试详解
2013/06/06 PHP
php实现的CSS更新类实例
2014/09/22 PHP
PHP随机数 C扩展随机数
2016/05/04 PHP
php关闭warning问题的解决方法
2016/05/17 PHP
php中字符串和整数比较的操作方法
2019/06/06 PHP
飞鱼(shqlsl) javascript作品集
2006/12/16 Javascript
关于javascript中的typeof和instanceof介绍
2012/12/04 Javascript
Raphael一个用于在网页中绘制矢量图形的Javascript库
2013/01/08 Javascript
jQuery ReferenceError: $ is not defined 错误的处理办法
2013/05/10 Javascript
jQuery创建DOM元素实例解析
2015/01/19 Javascript
jquery表单验证插件(jquery.validate.js)的3种使用方式
2015/03/28 Javascript
如何解决easyui自定义标签 datagrid edit combobox 手动输入保存不上
2015/12/26 Javascript
Vue.js实战之利用vue-router实现跳转页面
2017/04/01 Javascript
详解前端路由实现与react-router使用姿势
2017/08/07 Javascript
Node.JS中快速扫描端口并发现局域网内的Web服务器地址(80)
2017/09/18 Javascript
cordova入门基础教程及使用中遇到的一些问题总结
2017/11/14 Javascript
详解vue通过NGINX部署在子目录或者二级目录实践
2018/09/03 Javascript
js canvas画布实现高斯模糊效果
2018/11/27 Javascript
vue使用pdfjs显示PDF可复制的实现方法
2018/12/14 Javascript
vue element动态渲染、移除表单并添加验证的实现
2019/01/16 Javascript
vue实现列表拖拽排序的功能
2020/11/02 Javascript
跟老齐学Python之画圈还不简单吗?
2014/09/20 Python
Pyspider中给爬虫伪造随机请求头的实例
2018/05/07 Python
python绘制简单彩虹图
2018/11/19 Python
浅谈PyTorch中in-place operation的含义
2020/06/27 Python
10个python爬虫入门实例(小结)
2020/11/01 Python
员工培训邀请函
2014/01/11 职场文书
入党自我评价优缺点
2014/01/25 职场文书
环保标语口号
2014/06/13 职场文书
公司活动总结怎么写
2014/06/25 职场文书
爱的承诺书
2015/01/20 职场文书
2015年六一儿童节活动总结
2015/02/11 职场文书
女人创业励志语录,句句蕴含能量,激发你的潜能
2019/08/20 职场文书
【海涛解说】pis亲自推荐,其实你从来不会玩NW
2022/04/01 DOTA