javascript获取星座代码

  javascript获取星座源代码

<script>
    //javascript获取星座函数
    //@month:月份,注意从1开始。日期对象是从0开始
    //@date:日期
    function getStar(month, date) {
        var star = {
            "魔羯座": [[12, 22], [1, 19]], "水瓶座": [[1, 20], [2, 18]], "双鱼座": [[2, 19], [3, 20]], "白羊座": [[3, 21], [4, 19]],
            "金牛座": [[4, 20], [5, 20]], "双子座": [[5, 21], [6, 21]], "巨蟹座": [[6, 22], [7, 22]], "狮子座": [[7, 23], [8, 22]],
            "处女座": [[8, 23], [9, 22]], "天秤座": [[9, 23], [10, 23]], "天蝎座": [[10, 24], [11, 22]], "射手座": [[11, 23], [12, 21]]
        };
        for (var attr in star) {
            if (
                (month == star[attr][0][0] && date >= star[attr][0][1]) ||
                (month == star[attr][1][0] && date <= star[attr][1][1])
                )
                return attr;
        }
    }
    var d = new Date();
    alert(d.toLocaleDateString()+':'+getStar(d.getMonth() + 1, d.getDate()));
    d = new Date('2016/1/5');
    alert(d.toLocaleDateString() + ':' + getStar(d.getMonth() + 1, d.getDate()));
    d = new Date('2016/11/23');
    alert(d.toLocaleDateString() + ':' + getStar(d.getMonth() + 1, d.getDate()));
</script>

 

加支付宝好友偷能量挖...


原创文章,转载请注明出处:javascript获取星座代码

评论(0)Web开发网
阅读(295)喜欢(0)JavaScript/Ajax开发技巧