Add some JSCodeImplement the "clear" button
< Script Type = " Text/JavaScript " >
$ (Function (){
$ ( " # Datepicker " ). Datepicker ({closetext: ' X ' , Showbuttonpanel: True , Showclearbutton: True , Mindate: New Date ( 2009 , 7 , 10 )});
});
</ Script >
Description of automatic date range ban:
< Script Type = " Text/JavaScript " >
$ (Function (){
$ (" # Start-Date " ). Datepicker (
{Onselect: function (datetext, insT) {$ ( ' # End-date ' ). Datepicker ( ' Option ' , ' Mindate ' , New Date (datetext. Replace ( ' - ' , ' , ' )));}
});
$ ( " # End-date " ). Datepicker (
{Onselect: function (datetext, insT) {$ ( ' # Start-Date ' ). Datepicker ( ' Option ' , ' Maxdate ' , New Date (datetext. Replace ( ' - ' , ' , ' )));}
});
});
</ Script >
ProgramDownload the source code and more examples of datepicker usage:
/Files/Yasin/jquery_datepicker.zip
Datepicker official address:
Http://docs.jquery.com/UI/API/1.7/Datepicker#method-option
The date format is automatically verified after the focus is lost
_ Doblur: function ( Event )
{
VaR Inst = $. Datepicker. _ getinst ( Event . Target );
If(Inst. Input [0]. Value. Length=0)//Allowed to be empty
Return;
VaR Reg =/^ (\ D { 4 })(\ /|- ) (\ D { 1 , 2 })\ 2 (\ D { 1 , 2 }) $ / ;
VaR arr = Inst. Input [ 0 ]. Value. Match (REG)
If (ARR = Null )
{
Alert ( " Incorrect time format. Enter \ n in the format, for example, 2012-12-22. " );
VaR today = New Date (); // Set to current date
Inst. Input [ 0 ]. Value = Today. getyear () + " - " + (Today. getmonth () + 1 ) + " - " + Today. getdate ();
Inst. Input [ 0 ]. Focus ();
Return ;
}
VaR tempdate = New Date (ARR [ 1 ], Arr [ 3 ] - 1 , Arr [ 4 ]);
If (Tempdate. getfullyear () = Arr [ 1 ] && (Tempdate. getmonth () + 1 ) = Arr [ 3 ] && Tempdate. getdate () = Arr [ 4 ]) = False )
{
Alert ( " Incorrect time format. Enter \ n in the format, for example, 2012-12-22. " );
VaR today = New Date (); // Set to current date
Inst. Input [ 0 ]. Value = Today. getyear () + " - " + (Today. getmonth () + 1 ) + " - " + Today. getdate ();
Inst. Input [ 0 ]. Focus ();
Return ;
}
},