HTML:
<tablewidth="100%"class="td-min-height"border="1">
<tbody>
<trclass="firstRow">
<tdwidth="1373"valign="top">
<p>
<imgname="OTHER_1"title="日期控件:开始"align="absMiddle"class="DATE"style="width:18px; height:18px; cursor: pointer;"alt=""src="/static/images/form/calendar.png"border="0"value="开始"date_format="yyyy-MM-dd HH:00"classname="DATE"/><inputname="DATA_65"title="开始"align="left"style="text-align: left;"onkeyup="enfocus()"onclick="enfocus()"type="text"hidden="0"/>
</p>
<p>
<imgname="OTHER_2"title="日期控件:结束"align="absMiddle"class="DATE"style="width:18px; height:18px; cursor: pointer;"alt=""src="/static/images/form/calendar.png"border="0"value="结束"date_format="yyyy-MM-dd HH:00"classname="DATE"/><inputname="DATA_66"title="结束"align="left"style="text-align: left;"onkeyup="enfocus()"onclick="enfocus()"type="text"hidden="0"/>
</p>
<p>
时间差:<inputname="DATA_67"title="时间差"align="left"id="DATA_67"onclick="enfocus()"style="text-align: left;"type="text"hidden="0"/>
</p>
</td>
</tr>
</tbody>
</table>
<p>
<br/>
</p>
JS(请假等):
function enfocus()
{
var t1 = document.forms[0].DATA_65.value;
var t2 = document.forms[0].DATA_66.value;
var t3 = document.forms[0].DATA_67.value;
var date1 =newDate(t1);
var date2 =newDate(t2);
if(date1.toLocaleDateString()== date2.toLocaleDateString()){
if(date1.getHours()> date2.getHours())
{document.getElementById("DATA_67").value ="error";}
elseif(date1.getHours()<=12&& date2.getHours()>=13)
{document.getElementById("DATA_67").value = date2.getHours()-date1.getHours()-1;}
else
{document.getElementById("DATA_67").value = date2.getHours()-date1.getHours();}
}
elseif(date1.toLocaleDateString()< date2.toLocaleDateString()){
if(date1.getHours()<=12){
date1.setHours(date1.getHours()+1);
}
if(date2.getHours()>=13){
date2.setHours(date2.getHours()-1);
}
var a = date1.toLocaleDateString();
//将时间转换成年月日(去掉小时数)
var a1 =newDate(a);
//将时间转换成标准格式
var time1 = a1.getTime();
//将时间装换成毫秒
var b = date2.toLocaleDateString();
var b1 =newDate(b);
var time2 = b1.getTime();
var firstday;
firstday =18- date1.getHours();
var lastday;
lastday = date2.getHours()-9;
var day;
day =(time2-time1)/86400000-1;
var hours;
hours = firstday + lastday + day*8;
document.getElementById("DATA_67").value = hours;
}
else{document.getElementById("DATA_67").value ="error";}
}
JS(加班):
function enfocus()
{
var t1 = document.forms[0].DATA_65.value;
var t2 = document.forms[0].DATA_66.value;
var t3 = document.forms[0].DATA_67.value;
var date1 =newDate(t1);
var date2 =newDate(t2);
if(date1.toLocaleDateString()== date2.toLocaleDateString()){
if(date1.getHours()< date2.getHours()&& date1.getHours()==18)
{document.getElementById("DATA_67").value = date2.getHours()-date1.getHours()-1;}
elseif(date1.getHours()< date2.getHours()&& date1.getHours()>18)
{document.getElementById("DATA_67").value = date2.getHours()-date1.getHours();}
else
{document.getElementById("DATA_67").value ="error";}
}
elseif(date1.toLocaleDateString()< date2.toLocaleDateString()&&
date1.getHours()>=18&& date2.getHours()<=9){
if(date1.getHours()==18){
date1.setHours(date1.getHours()+1);}
var firstday;
firstday = date1.getHours();
var lastday;
lastday = date2.getHours();
var hours;
hours =24- firstday + lastday;
document.getElementById("DATA_67").value = hours;
}
else{document.getElementById("DATA_67").value ="error";}
}