js 根据日期做星座联动,简洁

    $('#constellation').mousedown(function(){
var constellations = new Array();
    /*  
因本人数据库存的数据是数字,
所以我需要返回星座来找到对应的数字,
可根据实际情况改变
*/
      constellations['白羊座'] = "1";
constellations['金牛座'] = "2";
constellations['双子座'] = "3";
constellations['巨蟹座'] = "4";
constellations['狮子座'] = "5";
constellations['处女座'] = "6";
constellations['天秤座'] = "7";
constellations['天蝎座'] = "8";
constellations['射手座'] = "9";
constellations['摩羯座'] = "10";
constellations['水瓶座'] = "11";
constellations['双鱼座'] = "12";

var birth = $('#dateBirth').val();
if(birth !==''){
var m = birth.substr(5,2);
var d = birth.substr(8,2);
var consname = getAstro(m,d)+'座';
$("#constellation").html('<option value="'+constellations[consname]+'">'+consname+'</option>');

}

})


});
function getAstro(m,d){

return "魔羯水瓶双鱼白羊金牛双子巨蟹狮子处女天秤天蝎射手魔羯".substr(m*2-(d<"102123444543".charAt(m-1)- -19)*2,2);
// return m-(d<"102223444433".charAt(m-1)- -19);
}
posted @ 2016-07-06 10:56  不融入  阅读(447)  评论(0编辑  收藏  举报