html+js实现输入用户名和密码点击登录跳转页面

html+js实现:

  • 输入用户名和密码点击登录跳转其他页面
  • 这里主页是index.html
  • 跳转的页面名字是随机点名.html

1.index.html


<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>	
	用户名:<input type="text" id="name">
					<br/>
		密&nbsp; &nbsp; 码:<input type="text" id="pwd"><br />
		&nbsp; &nbsp; &nbsp; <input type="button" value="提交" onclick="confime()" />
		&nbsp; &nbsp; <input type="button" value="查看" onclick="displaycooikes()" />

<script>
	function confime(){
		var sname=document.getElementById("name").value
		var spwd=document.getElementById("pwd").value
		if(sname=="admin"&&spwd=="admin"){
			window.open("随机点名.html")
		}
		else
		{
			alert("用户名或密码错误!");		
		}
				
	}
	function displaycooikes(){
		var myname= new Array()
		var myvalue= new Array()
		var str=""
		var cookiesstring=document.cookie
		var cookiessarray = cookiesstring.split(";")
		for(var i=0;i<cookiessarray.length;i++){
			var cookienum= cookiessarray[i].split("=")
			myname[i]=cookienum[0]
			myvalue[i]=cookienum[1]
		}
		alert(cookiesstring)
		alert("cookies信息是"+myname[0]+myvalue[0]+myname[1]+myvalue[1])
	}
</script>
				 
	
	</body>
</html>

 2.随机点名.html

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body>
		<center>
		<div id="d">
			<div id="name" style="width: 40px;height: 50px;">
			
			</div>
			
			<button id='start' type="button" >开始</button>
			<button id='temp' type="button" >暂停</button>
		</div>
		</center>
	</body>
</html>
<script type="text/javascript">
window.onload=function(){
var names =['张三','李四','王五','王麻子','小红'];//人名数组
var clors =[ '#EE0000' ,'#CAE1FF' , '#008B8B' , '#CDC9C9', '#FOF8FF'];//颜色数组
var name = document.getElementById( 'name');//获取id为name的元素
var d = document.getElementById( 'd');
var temp = document.getElementById( 'temp');
var start = document.getElementById( 'start');
function Random(){//产生随机数,并更改h1中的内容与颜色
	var nNum = Math.floor(Math.random()*5);//这里的5为你当前人名的数量
	var cNum = Math.floor(Math.random()*5);
	name.innerHTML = names[nNum];
	d.style.color=clors[cNum];
}
start.onclick = function(){//单击开始方法
	startR = setInterval(Random, 25);//设置计时器,每0.025秒执行一次
}
temp.onclick = function(){//单击暂停方法
	clearInterval(startR);
}
}
	
</script>

猜你喜欢

转载自blog.csdn.net/m0_54256047/article/details/128474310