クッキーケース登録ログイン

4160 ワード

register.html



	
		
		
		<style type="text/css">
			div {
				width: 300px;
				padding: 20px;
				border: 1px solid black;
				border-radius: 10px;
				margin: 50px auto;
			}
		</style>
	

	
		<div id="box">
			 :<input type="text" id="userName" value=""/><br/><br/>    :
			<input type="password" id="pwd" value=""/><br/><br/>
			<input style="width: 80px;border-radius: 5px; font-size: 18px;" type="button" id="register" value=" "/>
		</div>
	


<script type="text/javascript" src="public.js">
</script>
<script type="text/javascript">
	$id("register").onclick = function() {
		var unameVal = $id("userName").value;
		var pwdVal = $id("pwd").value;
		var arr = [{
			"userName": unameVal,
			"pwd": pwdVal
		}]
		var jsonStr = JSON.stringify(arr);
		if (document.cookie) {
			var flag = false;
			var cookieArr = document.cookie.split("; ");
			for (var i = 0; i < cookieArr.length; i++) {
				var uname = cookieArr[i].split("=")[0];
				if (uname == "user") {
					var userName = cookieArr[i].split("=")[1];
					flag = true;
					break;
				}
			}
			if (flag) {
				var flage = false;
				var JSONstr = JSON.parse(userName);
				for (var i = 0; i < JSONstr.length; i++) {
					if (JSONstr[i].userName == unameVal){
					flage = true;
				}
			}
			if (flage) {
				alert(" , ");
			} else {
				var userInfoJson = JSON.parse(userName);
				var obj = {
					"userName": unameVal,
					"pwd": pwdVal
				}
				userInfoJson.push(obj);
				var userInfostr = JSON.stringify(userInfoJson);
				document.cookie = "user=" + userInfostr;
				alert(" ");
				window.location.href = "login.html";
			}
		} else {
			document.cookie = "user=" + jsonStr;
			alert(" ");
			window.location.href = "login.html";
		}
	} else {
		document.cookie = "user=" + jsonStr;
		alert(" ");
		window.location.href = "login.html";
	}
	}
</script></code></pre> 
  <p>login.html</p> 
  <pre><code>

	
		<meta charset="UTF-8"/>
		<title/>
		<style type="text/css">
			div{
				width: 300px;
				padding: 20px;
				border: 1px solid black;
				border-radius: 10px;
				margin: 50px auto;
			}
		</style>
	
	
		<div id="box">
			 :<input type="text" id="userName" value=""/><br/><br/>
			   :<input type="password" id="pwd" value=""/><br/><br/>
			<input style="width: 80px;border-radius: 5px; font-size: 18px;" type="button" id="login" value=" "/>
		</div>
	

<script src="public.js"/>
<script type="text/javascript">
	
	// 
	$id("login").οnclick=function(){
		var userunmae=$id("userName").value;
		var usepwd=$id("pwd").value;
		var userInfo=getCookie("user");
		var userInfoArr=JSON.parse(userInfo);
		var flag=false;
		for(var i=0;i<userInfoArr.length;i++){
			if(userInfoArr[i].userName==userunmae){
				flag=true;
				break;
			}
		}
		if(flag){
			alert(" ");
			location.href="success.html?userName="+userunmae;
		}else{
			alert(" ");
		}
		
	}
</script></code></pre> 
  <p>success.html</p> 
  <pre><code>

	
		<meta charset="UTF-8"/>
		<title/>
	
	
		<h1> <span id="userName">xx</span> </h1>
	

<script type="text/javascript">
	var userName=document.getElementById("userName");
	userName.innerHTML=location.href.split("=")[1];
</script></code></pre> 
  <p> </p> 
 </div> 
</div>
                            </div>
                        </div>