JavaScript:输入月份: 显示当月的天数

var month = 7;
var year  = new Date().getFullYear();
switch(month) {
   case 1:
   case 3:
   case 5:
   case 7:
   case 8:
   case 10:
   case 12:
      alert(`${year}年${month}月有31天`);
      break;
   case 2:
      var year = new Date().getFullYear();
      if (year % 2 == 0 && year % 100 != 0 || year % 400 == 0) {
          alert(`${year}年${month}月29天`);    
      } else {
          alert(`${year}年${month}月28天`);
      }
      break;
   default:
      alert(`${year}年${month}月30天`);
      break;
}


原文地址:https://www.cnblogs.com/qjuly/p/13258554.html