有开始年月日文本框,终止年月日文本框,输入日期后,怎样判断,输入的日期是不是一个月的?
就是说,假如输入 2009年1月1日---2009年4月1日一共三个月就不行,就是说要判断输入的这个日期范围是不是一个月,怎么判断啊?

解决方案 »

  1.   


    var startDate = '2009年1月1日', endDate = '2009年4月1日';
    startDate = startDate.substr(0,startDate.length - 2).replace(/[^0-9]/g, '/');
    endDate = endDate.substr(0,endDate.length - 2).replace(/[^0-9]/g, '/');
    var d1 = new Date(startDate), d2 = new Date(endDate);
    if(!(d1.getFullYear() == d2.getFullYear() && d1.getMonth() == d2.getMonth())) {
        alert('不是同一个月');
    }
      

  2.   

    这样的情况只能两日期比较了。
    http://http://www.haixiait.com/article.asp?id=5
      

  3.   

    一点小错误,重来:
        var startDate = '2009年1月1日', endDate = '2009年1月1日';
        startDate = startDate.substr(0, startDate.length - 1).replace(/[^0-9]/g, '/');
        endDate = endDate.substr(0, endDate.length - 1).replace(/[^0-9]/g, '/');
        var d1 = new Date(startDate), d2 = new Date(endDate);
        if (!(d1.getFullYear() == d2.getFullYear() && d1.getMonth() == d2.getMonth())) {
            alert('不是同一个月');
        }