var years=prompt("请输入您的出生年份"); var months=prompt("请输入您的出生月份"); var days=prompt("请输入您的出生日期"); //判断用户输入格式 function userText(){ if(isNaN(years) && isNaN(months) && isNaN(days)){ alert("必须输入数字"); return false; } if(!(years&&months&&days)){ alert("不能为空"); return false; } if(months<=0 || months>12){ alert("请输入正确的月份!"); return false; }else{ return true;} } //判断闰年 function isLeapYear(){ return (years%4==0 && years%100!=0 || years%400==0) } // 整理每个月的天数 var monthDay=[31,28,31,30,31,30,31,31,30,31,30,31]; var monthnub=parseInt(months); function numDay(){ switch(parseInt(months)){ case 1: return parseInt(days); break; case 2: return parseInt(days)+monthDay[0]; break; if(isLeapYear()){ monthDay[1]=29; } case 3: return parseInt(days)+monthDay[0]+monthDay[1]; break; case 4: return parseInt(days)+monthDay[0]+monthDay[1]+monthDay[2]; break; case 5: return parseInt(days)+monthDay[0]+monthDay[1]+monthDay[2]+monthDay[3]; break; case 6: return parseInt(days)+monthDay[0]+monthDay[1]+monthDay[2]+monthDay[3]+monthDay[4]; break; case 7: return parseInt(days)+monthDay[0]+monthDay[1]+monthDay[2]+monthDay[3]+monthDay[4]+monthDay[5]; break; case 8: return parseInt(days)+monthDay[0]+monthDay[1]+monthDay[2]+monthDay[3]+monthDay[4]+monthDay[5]+monthDay[6]; break; case 9: return parseInt(days)+monthDay[0]+monthDay[1]+monthDay[2]+monthDay[3]+monthDay[4]+monthDay[5]+monthDay[6]+monthDay[7]; break; case 10: return parseInt(days)+monthDay[0]+monthDay[1]+monthDay[2]+monthDay[3]+monthDay[4]+monthDay[5]+monthDay[6]+monthDay[7]+monthDay[8]; break; case 11: return parseInt(days)+monthDay[0]+monthDay[1]+monthDay[2]+monthDay[3]+monthDay[4]+monthDay[5]+monthDay[6]+monthDay[7]+monthDay[8]+monthDay[9]; break; case 12: return parseInt(days)+monthDay[0]+monthDay[1]+monthDay[2]+monthDay[3]+monthDay[4]+monthDay[5]+monthDay[6]+monthDay[7]+monthDay[8]+monthDay[9]+monthDay[10]; break; } } numDay(); isLeapYear(); userText(); document.write("你的生日是在" + years + "年的第" + numDay()+ "天");
请问numDay()里面的函数该如何简化,实在是js很新很新的新人。麻烦大牛修改一下,能让我看得懂的方法
qq_青枣工作室_0
我爱吃牛排
相关分类