我正在使用这个脚本,因为我需要关注每个警报。我尝试了很多方法,但它不起作用。
脚本:
function validateTime(obj) {
var timeValue = obj.value;
if(timeValue == "" || timeValue.indexOf(":") < 0) {
alert("Invalid Time format");
obj.value = "";
return false;
} else {
var sHours = timeValue.split(':')[0];
var sMinutes = timeValue.split(':')[1];
if(sHours == "" || isNaN(sHours) || parseInt(sHours) > 23) {
alert("Invalid Time format");
obj.value = "";
return false;
} else if(parseInt(sHours) == 0) sHours = "00";
else if(sHours < 10) sHours = "0" + sHours;
if(sMinutes == "" || isNaN(sMinutes) || parseInt(sMinutes) > 59) {
alert("Invalid Time format");
return false;
} else if(parseInt(sMinutes) == 0) sMinutes = "00";
else if(sMinutes < 10) sMinutes = "0" + sMinutes;
obj.value = sHours + ":" + sMinutes;
}
return true;
}
aspx:
<asp:TextBox ID="lblMonday" CssClass="lblMonday" runat="server" Width="55px" onchange="validateTime(this);"></asp:TextBox>