Jquery automatically adds the current date to the date plug-in when loading the page.
The current date is automatically added to the date plug-in when the page is loaded.
<script type="text/javascript">$(document).ready(function(){$("#startTime").val(formatDate());$("#endTime").val(formatDate());}
Code of the jsp page body:
<Td> <label> date: </label> </td> <input type = "text" id = "startTime">: <input type = "text" id = "endTime"> </td>
I now have two text boxes, the first selected the date, the second automatically display the first date plus the 280 day, using js or jquery to implement
<Script type = "text/javascript">
Function test (){
// The date format must be yyyy-mm-dd. the month and the day do not contain 0, for example, 2011-3-2.
Var date1 = document. getElementById ('date1'). value;
Var date = new Date (date1.split ('-') [0], date1.split ('-') [1]-1, date1.split ('-') [2]);
Date. setDate (date. getDate () + 280 );
Var date2 = date. getFullYear () + '-' + (date. getMonth () + 1) + '-' + date. getDate ();
Document. getElementById ('date2'). value = date2;
}
</Script>
<Body>
The first date: <input id = "date1" type = "text" onblur = "test ();"/>
Second date: <input id = "date2" type = "text" readonly = "readonly"/>
</Body>
Tutorial: Does jquery dynamically Add a date control not work?
The input box you added dynamically is not automatically initialized by the calendar control.
The reason is that when you initialize the calendar control, there are no such elements on the page.
You can only do this.
$ (Function (){
$. Datepicker. setDefaults ($. datepicker. regional ['zh-cn']);
Function initDatePicker (ele ){
Ele. datepicker ({
DateFormat: "yy-mm-dd ",
AutoSize: true,
})
InitDatePicker ($ (". datepicker "));
}
$ ("# AddRow"). click (function (){
Var $ tr = $ ("<tr> </tr> ");
Var $ td1 =$ ("<td> </td> ");
Var dateInput = $ ("<input type = \" text \ "class = \" datepicker \ "style = \" width: 70px; \ "> ")
$ Td1.append (dateInput );
$ Td1.appendTo ($ tr );
$ Tr. appendTo ("# tab ");
InitDatePicker (dateInput );
}
)