function isTime(s){
var str=$("#"+s).val();
if(str!=null&&str!=""){
var f=document.getElementById(s);
if(str.length == 5){
var j=str.indexOf(":");
var hour=str.substring(0,j);
var minute=str.substring(j+1);
if(j==-1){
alert("时间格式hh:mm");
f.focus();//获得焦点
return false;
}
if (hour>=24||minute>=60){
alert("输入范围时间格式有误!");
f.focus();
return false;
}
if (hour==23&&minute!=00){
return true;
}
}else {
alert("时间格式hh:mm");
f.focus();
return false;
}
var a = str.match(/^(\d{1,2})(:)?(\d{1,2})$/);
if (a == null){
alert("时间格式hh:mm");
f.focus();
return false;
}
if (a[1]>24||a[3]>60){
alert("时间格式hh:mm");
f.focus();
return false;
}
}
return true;
}
<tr>
<td align="right" width="55px" class="label-cell">
<span style="color: red;">*</span>时段名称
</td>
<td>
<s:textfield name="period.name" id="periodname"></s:textfield>
</td>
<td align="right" width="60px" class="label-cell">
开始签到时间
</td>
<td>
<s:textfield id="periodcheckInTime1" name="period.checkInTime1" οnblur="isTime('periodcheckInTime1')"></s:textfield>
<s:hidden name="period.periodId" />
</td>
</tr>
<tr>
<td align="right" width="55px" class="label-cell">
<span style="color: red;">*</span>上班时间
</td>
<td>
<s:textfield name="period.startTime" id="periodStartTime" οnblur="isTime('periodStartTime')"></s:textfield>
</td>
<td align="right" width="60px" class="label-cell">
结束签到时间
</td>
<td>
<s:textfield id="periodcheckInTime2" name="period.checkInTime2" οnblur="isTime('periodcheckInTime2')"></s:textfield>
</td>
</tr>
<tr>
<td align="right" width="55px" class="label-cell">
<span style="color: red;">*</span>下班时间
</td>
<td>
<s:textfield name="period.endTime" id="periodEndTime" οnblur="isTime('periodEndTime')"></s:textfield>
</td>
<td align="right" width="60px" class="label-cell">
开始签退时间
</td>
<td>
<s:textfield id="periodcheckOutTime1" name="period.checkOutTime1" οnblur="isTime('periodcheckOutTime1')"></s:textfield>
</td>
</tr>
<tr>
<td align="right" width="60px" class="label-cell">
记迟到时间(分钟)
</td>
<td>
<s:textfield name="period.lateMinutes"></s:textfield>
</td>
<td align="right" width="60px" class="label-cell">
结束签退时间
</td>
<td>
<s:textfield id="periodcheckOutTime2" name="period.checkOutTime2" οnblur="isTime('periodcheckOutTime2')"></s:textfield>
</td>
</tr>
<tr>
<td align="right" width="60px" class="label-cell">
记早退时间(分钟)
</td>
<td>
<s:textfield name="period.earlyMinutes"></s:textfield>
</td>
</tr>
判断文本框为时间格式HH:mm
最新推荐文章于 2022-01-04 14:12:47 发布