格式化海员输入时间的习惯

/ 0评 / 0

[code lang="js"]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>格式化时间</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="text" id="timeFormat" maxlength="4" onblur="timeFormater()" />
</div>
</form>
<script type="text/javascript">
var timer = document.getElementById("timeFormat");
function timeFormater() {
if (isNaN(timer.value) == false) {
timer.maxLength = 5;
var time = timer.value.split("");
timer.value = time[0] + time[1] + ":" + time[2] + time[3];
}
else {alert("please input number");}
}
</script>
</body>
</html>
[/code]

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注