login2
This commit is contained in:
@@ -34,10 +34,28 @@
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<form action="" class="login-form">
|
||||
<form action="./main.html" class="login-form" method="post" onsubmit="return login()">
|
||||
<h1>在线聊天系统</h1>
|
||||
<input type="text">
|
||||
<input type="text" name="nickname" required="true">
|
||||
<input type="submit" value="登录">
|
||||
</form>
|
||||
|
||||
<script type="text/javascript">
|
||||
function login() {
|
||||
var element=document.getElementsByName('nickname')[0]
|
||||
var nickname=element.value
|
||||
localStorage.setItem('nickname',nickname)
|
||||
return true
|
||||
}
|
||||
|
||||
//检查登录用户名
|
||||
window.onload=function () {
|
||||
var nickname=localStorage.getItem('nickname')
|
||||
if(nickname){
|
||||
window.onload.href='./main.html'
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,34 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>在线聊天系统</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1 id="hello_text">欢迎使用在线聊天系统</h1>
|
||||
<button onclick="quit()">注销</button>
|
||||
<script type="text/javascript">
|
||||
window.onload=function () {
|
||||
var nickname=localStorage.getItem('nickname')
|
||||
if(nickname){
|
||||
//昵称存在,显示昵称
|
||||
var element=document.getElementById("hello_text")
|
||||
element.innerText=nickname+",欢迎使用在线聊天系统"
|
||||
}
|
||||
else {
|
||||
//昵称不存在,跳转 到登录页面
|
||||
window.location.href='./index.html'
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//注销函数
|
||||
function quit() {
|
||||
localStorage.removeItem('nickname');
|
||||
window.location.href='./index.html'
|
||||
}
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user