详见代码。
具体代码如下:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html charset=UTF-8">
<link href="css/regist.css" rel="stylesheet" type="text/css">
<title>网上购物系统</title>
<script type="text/javascript">
var reg=/^[a-zA-Z]\w*$/
var flag1=false,flag2=false,flag3=false
function chang1(obj){
var name=obj.value
if(name.length<3||name.length>8){
//alert("密码要求3-8位!")
document.getElementById("usName").innerHTML="<font color='red'> 用户名要求3-8位!</font>"
}
else if(!reg.test(name)){
//alert("用户名由字母开头,后字母、数字或下划线!")
document.getElementById("usName").innerHTML="<font color='red'> 用户名由字母开头,后字母、数字或下划线</font>"
flag1=false
<form action = "a.html" method = "post">用户名:<input type = "text" name = "username" id = "username">
<br>
密码:<input type = "password" name = "password" id = "password">
<br>
<input type = "submit" id = "submit" value = "登录">
</form>
使用js的getDate()。getTime() 返回从 1970 年 1 月 1 日至今的毫秒数用当前时间的毫秒数减去用户输入的时间的毫秒数即相差的时间
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<p id="demo">单击按钮显示1970年1月1号至生日的毫秒数。</p>
<p id="demo1">单击按钮显示1970年1月1号至今的毫秒数。</p>
<p id="demo2">单击按钮显示相差的毫秒数。</p>
<button onclick="myFunction()">点我</button>
<script>
function myFunction(){
var d = new Date()
var x = document.getElementById("demo")
x.innerHTML+=d.getTime()/1000 + "s\n"
x.innerHTML+=d.getTime()/1000/60 + "m\n"
x.innerHTML+=d.getTime()/1000/60/60 + "h\n"
x.innerHTML+=d.getTime()/1000/60/60/24 + "d\n"
x.innerHTML+=d.getTime()/1000/60/60/24/366 + "y\n"
var x2=d.getTime()/1000/60/60/24/366
var myDate=new Date(),y = document.getElementById("demo1"),z = document.getElementById("demo2")
myDate.setFullYear(2010,0,14)
y.innerHTML+=myDate.getTime()/1000 + "s\n"
y.innerHTML+=myDate.getTime()/1000/60 + "m\n"
y.innerHTML+=myDate.getTime()/1000/60/60 + "h\n"
y.innerHTML+=myDate.getTime()/1000/60/60/24 + "d\n"
y.innerHTML+=myDate.getTime()/1000/60/60/24/366 + "y\n"
var x1 =myDate.getTime()/1000/60/60/24/366
z.innerHTML+= x2 - x1 + "y\n"
}
</script>
</body>
</html>