如何比较javascript中的两个文本框日期 [英] how compare two textbox dates in javascript
本文介绍了如何比较javascript中的两个文本框日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何比较javascript中的两个文本框日期
解决方案
你可以将字符串转换为日期然后比较这两个字符串
var Date1 = new 日期( 12/121/2012);
var Date2 = new 日期( 6/6/2013);
if (Date2> Date1)
{
alert(' 找到');
}
试用此代码:
< html xmlns = http ://www.w3.org/1999/xhtml >
< head id = Head1 runat = server >
< title > Untitled Page < / title >
< script > function date()
{
t1 = document .getElementById( text1)。value;
t2 = document .getElementById( text2 中跨度>)值。
var one_day = 1000 * 60 * 60 * 24;
var x = t1.split( /跨度>);
var y = t2.split( /跨度>);
var date1 = new 日期(x [ 2 ],(x [ 1 ] - 1),x [ 0 ]);
var date2 = new 日期(y [ 2 ],(y [ 1 ] - 1),y [ 0 ])
var month1 = x [ 1 跨度>] - 1;
var month2 = y [ 1 ] - 1;
_Diff = 数学 .ceil((date2.getTime() - date1.getTime())/(one_day));
if (_ Diff< 0)
{
alert( 选择正确的日期);
}
}
< / script >
< / head > < body >
< 表格 id = Form1 runat = server >
< 输入 type = text id = text1 / >
< input type = text id < span class =code-keyword> = text2 / >
< 输入 type = 按钮 value = 检查 onclick = date() / >
< / form >
< / body >
< / html > 跨度>
http://stackoverflow.com/questions/492994/compare-dates-with-javascript
查看以上链接。会帮助你。
-anurag
how compare two textbox dates in javascript
解决方案you can convert the strings to date and then compare the two strings like this
var Date1 = new Date("12/121/2012"); var Date2 = new Date("6/6/2013"); if (Date2 > Date1) { alert('found'); }
Try this code:
<html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title>Untitled Page</title> <script>function date() { t1=document.getElementById("text1").value; t2=document.getElementById("text2").value; var one_day=1000*60*60*24; var x=t1.split("/"); var y=t2.split("/"); var date1=new Date(x[2],(x[1]-1),x[0]); var date2=new Date(y[2],(y[1]-1),y[0]) var month1=x[1]-1; var month2=y[1]-1; _Diff=Math.ceil((date2.getTime()-date1.getTime())/(one_day)); if(_Diff<0) { alert("seelct correct date"); } } </script> </head> <body> <form id="Form1" runat="server" > <input type="text" id="text1" /> <input type="text" id="text2" /> <input type="button" value="check" onclick="date()" /> </form> </body> </html>
http://stackoverflow.com/questions/492994/compare-dates-with-javascript
check the above link.it will help you.
-anurag
这篇关于如何比较javascript中的两个文本框日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文