生辰八字网

浏览器上怎么设置显示星座

编写一个JAVASCRIPT 程序,弹出一个询问生日的对话框,计算出用...

借此自己也学习下,写了个小例子,你看看<script>function show(){var a=[['12-22','01-19','魔蝎座'],['01-20','02-18','水瓶座'],['02-19','03-20','双鱼座'],['02-21','05-20','白羊座'],['04-21','05-20','金牛座'],['05-21','06-21','双子座'],['06-22','07-22','巨蟹座'],['07-23','08-22','狮子座'],['08-23','09-22','处女座'],['09-23','10-22','天秤座'],['10-23','11-21','天蝎座'],['11-22','12-21','射手座']];var datePattern = /^(\d{4})-(\d{1,2})-(\d{1,2})$/; var birthday=window.prompt('输入你的出生年月日(格式如1985-10-15)','');try{if(!datePattern.test(birthday)&&birthday){alert('请输入正确的生日格式');}else{var b=new Date(Date.parse(birthday.replace('-','/')));d=datePattern.exec(birthday);s=RegExp.$1;for(var i=0;ivar start_date=new Date(Date.parse(s+'/'+a[i][0].replace('-','/')));var end_date=new Date(Date.parse((i==0?s-0+1:s)+'/'+a[i][1].replace('-','/')));if(b>=start_date&&bwindow.status='你的星座是:'+a[i][2];break;}}if(i=='12'){window.status='错误的出生日期,无法解析';}} }catch(e){alert("格式错误"+e);}}</script>

作者:八字算命 分类:星座 浏览: