jquery比较文本框中的两个日期 [英] jquery that compares two dates inside textboxes

查看:74
本文介绍了jquery比较文本框中的两个日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



i只想问下如何与以下场景比较日期:



1.我有两个带日期选择器的文本框。 [textbox1]和[textbox2]

2. [textbox2]日期不得小于[textbox1]内的日期



有任何javascript都可以吗?



谢谢。



[更新] [textbox1]日期不应该是小于当前日期。

hi all,

i just want to ask how to compare dates with the following scenario:

1. i have two textboxes that has date picker. [textbox1] and [textbox2]
2. [textbox2] Date must not be less than the date inside [textbox1]

is there any javascript to do it?

thanks.

[UPDATE] [textbox1] Date should not be less than the current date.

推荐答案

查看这篇文章你会有所了解 [ ^ ]


你好



尝试以下代码





Hello

Try to below code


var xDate=new Date();
xDate.setFullYear(2100,0,14);
var today = new Date();

if (xDate>today)
  {
  alert("Today is before 14th January 2100");
  }
else
  {
  alert("Today is after 14th January 2100");
  }





谢谢



Thanks






请尝试这个你可以得到解决方案(根据你的代码进行更改)。







Hi,

Please Try This one you can get solution (make changes as per your code).



function datevalidate2(dateFrom, dateTo)
  {
       var arr = dateFrom.split("-");
       var Fyear=arr[0];
       var Fmonth=arr[1];
       var Fday=arr[2];
       var arr1=dateTo.split("-");
       var Tyear=arr1[0];
       var Tmonth=arr1[1];
       var Tday=arr1[2];

       if(parseInt(Fyear)>parseInt(Tyear))
       {
           return false;
       }
       else if (parseInt(Fyear) == parseInt(Tyear) && parseInt(Fmonth) > parseInt(Tmonth))
       {
           return false;
       }
       else if (parseInt(Fyear) == parseInt(Tyear) && parseInt(Fmonth) == parseInt(Tmonth) && parseInt(Fday) > parseInt(Tday))
       {
           return false;
       }
       return true; 
  }


这篇关于jquery比较文本框中的两个日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆