$("input#startDate,input#endDate").live("blur focus",function(){
var startDate;
var endDate;
var hours;
if($.trim($(this).attr("value"))!=""){
if($.trim($(this).attr("id"))=="startDate"){
startDate=new Date($.trim($(this).attr("value")).replace(/-/g,"/"));
endDate=new Date($.trim($(this).parents("tr").find("input#endDate").attr("value")).replace(/-/g,"/"));
}else if($.trim($(this).attr("id"))=="endDate"){
startDate=new Date($.trim($(this).parents("tr").find("input#startDate").attr("value")).replace(/-/g,"/"));
endDate=new Date($.trim($(this).attr("value")).replace(/-/g,"/"));
}
var ms=endDate.getTime()-startDate.getTime(); //时间差的毫秒数
hours=ms/(3600*1000);
if(!isNaN(hours.toFixed(2))){
$(this).parents("tr").find("input#time").attr("value",hours.toFixed(2));
}
}
});
$("input#time").live("blur focus",function(){
var startDate;
var endDate;
var hours;
if($.trim($(this).attr("value"))!=""){
if($.trim($(this).parents("tr").find("input#startDate").attr("value"))!=""){
startDate=new Date($.trim($(this).parents("tr").find("input#startDate").attr("value")).replace(/-/g,"/"));
startDate.setHours(startDate.getHours()+parseFloat($(this).attr("value")));
var formatDate=startDate.getFullYear()+"-"+(startDate.getMonth()+1)+"-"+startDate.getDate()+" "+startDate.getHours()+":"+startDate.getMinutes()+":"+startDate.getSeconds();
$(this).parents("tr").find("input#endDate").attr("value",formatDate);
}else if($.trim($(this).parents("tr").find("input#endDate").attr("value"))!=""){
endDate=new Date($.trim($(this).parents("tr").find("input#endDate").attr("value")).replace(/-/g,"/"));
endDate.setHours(endDate.getHours()-parseFloat($(this).attr("value")));
var formatDate=endDate.getFullYear()+"-"+(endDate.getMonth()+1)+"-"+endDate.getDate()+" "+endDate.getHours()+":"+endDate.getMinutes()+":"+endDate.getSeconds();
$(this).parents("tr").find("input#startDate").attr("value",formatDate);
}
}
});
var startDate;
var endDate;
var hours;
if($.trim($(this).attr("value"))!=""){
if($.trim($(this).attr("id"))=="startDate"){
startDate=new Date($.trim($(this).attr("value")).replace(/-/g,"/"));
endDate=new Date($.trim($(this).parents("tr").find("input#endDate").attr("value")).replace(/-/g,"/"));
}else if($.trim($(this).attr("id"))=="endDate"){
startDate=new Date($.trim($(this).parents("tr").find("input#startDate").attr("value")).replace(/-/g,"/"));
endDate=new Date($.trim($(this).attr("value")).replace(/-/g,"/"));
}
var ms=endDate.getTime()-startDate.getTime(); //时间差的毫秒数
hours=ms/(3600*1000);
if(!isNaN(hours.toFixed(2))){
$(this).parents("tr").find("input#time").attr("value",hours.toFixed(2));
}
}
});
$("input#time").live("blur focus",function(){
var startDate;
var endDate;
var hours;
if($.trim($(this).attr("value"))!=""){
if($.trim($(this).parents("tr").find("input#startDate").attr("value"))!=""){
startDate=new Date($.trim($(this).parents("tr").find("input#startDate").attr("value")).replace(/-/g,"/"));
startDate.setHours(startDate.getHours()+parseFloat($(this).attr("value")));
var formatDate=startDate.getFullYear()+"-"+(startDate.getMonth()+1)+"-"+startDate.getDate()+" "+startDate.getHours()+":"+startDate.getMinutes()+":"+startDate.getSeconds();
$(this).parents("tr").find("input#endDate").attr("value",formatDate);
}else if($.trim($(this).parents("tr").find("input#endDate").attr("value"))!=""){
endDate=new Date($.trim($(this).parents("tr").find("input#endDate").attr("value")).replace(/-/g,"/"));
endDate.setHours(endDate.getHours()-parseFloat($(this).attr("value")));
var formatDate=endDate.getFullYear()+"-"+(endDate.getMonth()+1)+"-"+endDate.getDate()+" "+endDate.getHours()+":"+endDate.getMinutes()+":"+endDate.getSeconds();
$(this).parents("tr").find("input#startDate").attr("value",formatDate);
}
}
});