Blogger Information
Blog 18
fans 0
comment 0
visits 13470
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
JS实例全选反选 页面随机换色 倒计时跳转-3.28
太早的博客
Original
693 people have browsed it


页面变色及全选反选


实例

<!DOCTYPE html>
<html>
<head>
	<title>hello world!</title>
	<style type="text/css">
	div{width: 600px;margin: 100px auto;}
	table{width: 600px;border: 1px solid black;border-collapse: collapse;}
	td{border: 1px solid black;text-align: center;}
	</style>
</head>
<body>
	<button onclick="bg_Color()">点击变色</button>
	<div>
		<p>
			<button onclick="checkAll()">全选</button>
			<button onclick="checkOut()">反选</button>
		</p>
		<table>
			<thead>
				<tr>
					<th colspan="2">标题</th>
					<th>状态</th>
				</tr>
			</thead>
			<tbody>
				<tr>
					<td><input type="checkbox" name="list"></td>
					<td>标题一</td>
					<td>已读</td>
				</tr>
				<tr>
					<td><input type="checkbox" name="list"></td>
					<td>标题二</td>
					<td>已读</td>
				</tr>
				<tr>
					<td><input type="checkbox" name="list"></td>
					<td>标题三</td>
					<td>已读</td>
				</tr>
				<tr>
					<td><input type="checkbox" name="list"></td>
					<td>标题四</td>
					<td>已读</td>
				</tr>
				<tr>
					<td><input type="checkbox" name="list"></td>
					<td>标题五</td>
					<td>已读</td>
				</tr>
			</tbody>
		</table>
	</div>
	<script type="text/javascript">
		function bgColor(){
			var trList=document.getElementsByTagName("tbody")[0].getElementsByTagName("tr")
			for(var i=0;i<trList.length;i++){
				if(i%2){
					trList[i].style.background="pink";
				}else{
					trList[i].style.background="orange";
				}
			}
		}
		bgColor();
		function checkAll(){
			var objList=document.getElementsByName("list");
			for(var i=0;i<objList.length;i++){
				objList[i].checked=true;
			}
		}
		function checkOut(){
			var objList=document.getElementsByName("list");
			for(var i=0;i<objList.length;i++){
				if(objList[i].checked){
					objList[i].checked=false;
				}else{
					objList[i].checked=true;
				}
			}
		}
		function bg_Color(){
			var bg="#";
			var r=Math.floor(Math.random()*100).toString();
			var b=Math.floor(Math.random()*100).toString();
			var g=Math.floor(Math.random()*100).toString();
			bg+=r+b+g;
			document.getElementsByTagName("body")[0].style.background=bg;
		}
	</script>
</body>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例


页面倒计时跳转


实例

<!DOCTYPE html>
<html>
<head>
	<title>hello world!</title>
	<style type="text/css">
	p{width: 300px;margin:100px auto;}
	span{width: 50px;height: 50px;font-size: 50px;color: red;line-height: 50px;text-align: center;display: inline-block;}
	</style>
</head>
<body>
	<p>还剩<span>5</span>秒跳转至<a href="https://www.baidu.com">百度</a></p>
	<script type="text/javascript">
		var Espan=document.getElementsByTagName('span')[0];
		var i=4;
		function fn(){
			if(i>0){
				Espan.innerHTML=i;
				i--;
			}else{
				window.location.href="https://www.baidu.com";
			}
		}
		setInterval("fn()",1000)
	</script>
</body>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例


Correction status:Uncorrected

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!