For example, if you select start time, the end time is automatically assigned a value.
1. Page Introduction <SCRIPT type = "text/JavaScript" src = "../styles/JS/jquery-1.6.2.js"> </SCRIPT>
2. HTML code
<Tr> <TD class = "category"> Start Time: </TD> <input id = "starttime" name = "starttime" type = "text" onclick = "wdatepicker ({startdate: 'Current time', datefmt: 'yyyy-mm-dd hh: mm: ss'}) "onchange =" addhours (this. value) "/> <font color =" # ff0000 "> * </font> </TD> <TD class =" category "> End Time: </TD> <input id = "endtime" name = "endtime" type = "text" onclick = "wdatepicker ({startdate: 'Current time', datefmt: 'yyyy-mm-dd hh: mm: ss'}) "/> <font color =" # ff0000 "> * </font> </TD> </tr>
3. Redefinition of date objects
// Time format date. Prototype. format = function (Format) {/** eg: format = "yyyy-mm-dd hh: mm: SS"; */If (! Format) {format = "yyyy-mm-dd hh: mm: SS";} var o = {"m +": This. getmonth () + 1, // month "d +": This. getdate (), // Day "H +": This. gethours (), // Hour "m +": This. getminutes (), // minute "s +": This. getseconds (), // second "q +": math. floor (this. getmonth () + 3)/3), // quarter "S": This. getmilliseconds () // millisecond}; If (/(Y + )/. test (Format) {format = format. replace (Regexp. $1, (this. getfullyear ( ) + ""). Substr (4-Regexp. $1. length);} For (var k in O) {If (New Regexp ("(" + K + ")"). test (Format) {format = format. replace (Regexp. $1, Regexp. $1. length = 1? O [k]: ("00" + O [k]). substr ("" + O [k]). Length) ;}} return format ;};
4. js function declaration
function addHours(startTime){var start=new Date(startTime.replace("-", "/").replace("-", "/"));start.setHours(start.getHours()+2);$("#endTime").val(start.format("yyyy-MM-dd hh:mm:ss"));}