在javascript中检查年份是否是闰年

 function leapYear(year){
    var result; 
    year = parseInt(document.getElementById("isYear").value);
    if (years/400){
      result = true
    }
    else if(years/100){
      result = false
    }
    else if(years/4){
      result= true
    }
    else{
      result= false
    }
    return result
 }

这就是我目前所拥有的(条目是在一个 from 因此存储在isYear"中),我基本上遵循这个 这里,所以使用我已经拥有的,我如何根据这些条件检查条目是否是闰年(注意我在实现伪代码时可能做错了,如果我有,请纠正我)注意这需要使用整数而不是日期函数

This is what I have so far (the entry is on a from thus stored in "isYear"), I basically followed this here, so using what I already have, how can I check if the entry is a leap year based on these conditions(note I may have done it wrong when implementing the pseudocode, please correct me if I have) Note this needs to use an integer not a date function

推荐答案

function leapYear(year)
{
  return ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0);
}

相关文章