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函数ajax
Aug 20 Javascript
javascript 极速 隐藏/显示万行表格列只需 60毫秒
Mar 28 Javascript
使用JavaScript修改浏览器URL地址栏的实现代码
Oct 21 Javascript
3种Jquery限制文本框只能输入数字字母的方法
Dec 03 Javascript
javascript中类的定义方式详解(四种方式)
Dec 22 Javascript
JavaScript设计模式之代理模式详解
Jun 09 Javascript
node.js中grunt和gulp的区别详解
Jul 17 Javascript
vue.js element-ui validate中代码不执行问题解决方法
Dec 18 Javascript
完美解决mui框架off-canvas侧滑超出部分隐藏无法滚动的问题
Jan 25 Javascript
layer.msg()去掉默认时间,实现手动关闭的方法
Sep 12 Javascript
微信小程序服务器日期格式化问题
Jan 07 Javascript
解决echarts 一条柱状图显示两个值,类似进度条的问题
Jul 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
ZF等常用php框架中存在的问题
2008/01/10 PHP
php 将字符串按大写字母分隔成字符串数组
2010/04/30 PHP
php学习笔记(三)操作符与控制结构
2011/08/06 PHP
实测在class的function中include的文件中非php的global全局环境
2013/07/15 PHP
细品javascript 寻址,闭包,对象模型和相关问题
2009/04/27 Javascript
JS 去除Array中的null值示例代码
2013/11/20 Javascript
简单js代码实现selece二级联动(推荐)
2014/02/18 Javascript
Ext GridPanel加载完数据后进行操作示例代码
2014/06/17 Javascript
jquery JSON的解析方式示例介绍
2014/07/27 Javascript
解决jquery插件:TypeError:$.browser is undefined报错的方法
2015/11/21 Javascript
浅析JavaScript中的对象类型Object
2016/05/26 Javascript
jQuery文字提示与图片提示效果实现方法
2016/07/04 Javascript
JS中的hasOwnProperty()、propertyIsEnumerable()和isPrototypeOf()
2016/08/11 Javascript
JavaScript使用键盘输入控制实现数字验证功能
2016/08/19 Javascript
BootStrap Table前台和后台分页对JSON格式的要求
2017/06/28 Javascript
详解webpack编译多页面vue项目的配置问题
2017/12/11 Javascript
Vue-Router的使用方法
2018/09/05 Javascript
vue使用vuex实现首页导航切换不同路由的方法
2019/05/08 Javascript
微信小程序实现一个简单swiper代码实例
2019/12/30 Javascript
使用vant的地域控件追加全部选项
2020/11/03 Javascript
Python自动化测试工具Splinter简介和使用实例
2014/05/13 Python
学生信息管理系统python版
2018/10/17 Python
详解python读取和输出到txt
2019/03/29 Python
详解利用OpenCV提取图像中的矩形区域(PPT屏幕等)
2019/07/01 Python
python 单线程和异步协程工作方式解析
2019/09/28 Python
Pytorch 实现冻结指定卷积层的参数
2020/01/06 Python
python3.4中清屏的处理方法
2020/07/06 Python
详解使用canvas保存网页为pdf文件支持跨域
2018/11/23 HTML / CSS
美国折衷生活方式品牌:Robert Graham
2018/07/13 全球购物
售后服务科岗位职责范文
2013/11/13 职场文书
农民入党思想汇报
2014/01/03 职场文书
土木建筑学生自我评价
2014/01/14 职场文书
居住证明范文
2015/06/17 职场文书
演讲比赛通讯稿
2015/07/18 职场文书
退休欢送会致辞
2015/07/31 职场文书
导游词之澳门玫瑰圣母堂
2019/12/03 职场文书