jQuery小功能案例

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>隔行换色</title>
		<style type="text/css">
			table{
				margin: auto;
			}
			.color {
				background-color: deeppink;
			}
		</style>
	</head>
	<body>
		<table border="" cellspacing="" cellpadding="">
			<tr>
				<th>Header</th>
				<th>Header</th>
				<th>Header</th>
				<th>Header</th>
			</tr>
			<tr><td>Data</td>
				<td>Data</td>
				<td>Data</td>
				<td>Data</td>
			</tr>
			<tr><td>Data</td>
				<td>Data</td>
				<td>Data</td>
				<td>Data</td>
			</tr>
		</table>
	</body>
	<script type="text/javascript" src="js/jquery-3.1.1.js"> </script>
	<script type="text/javascript">
		/*这是简单写法,把这个打开,把后面的注掉即可查看.
		$("tr:even").addClass("color")
		$(document).click(function(){
			//toggleClass无则添加,有则删除
			$("tr:even").toggleClass("color");
			$("tr:odd").toggleClass("color");
		})*/
		var isEven = true;
		$(document).click(function() {
			if (isEven) {
				$("tr:even").addClass("color")
				$("tr:odd").removeClass("color");
			}else{
				$("tr:odd").addClass("color")
				$("tr:even").removeClass("color");
			}
			isEven = ! isEven;
		})
		
	</script>
</html>

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>全选/全不选</title>
	</head>
	<body>
		<table border="" cellspacing="" cellpadding="">
			<tr>
				
				<th><input type="checkbox" class="f" name="" id="" value="" /></th>
				<th>Header</th>
				<th>Header</th>
				<th>Header</th>
			</tr>
			<tr>
				 
				<td><input type="checkbox" class="s" name="" id="" value="" /></td>
				<td>Data</td>
				<td>Data</td>
				<td>Data</td>
			</tr>
			<tr>
				 
				<td><input type="checkbox" class="s"  name="" id="" value="" /></td>
				<td>Data</td>
				<td>Data</td>
				<td>Data</td>
			</tr>
			<tr>
				 
				<td><input type="checkbox" class="s"  name="" id="" value="" /></td>
				<td>Data</td>
				<td>Data</td>
				<td>Data</td>
			</tr>
			<tr>
				 
				<td><input type="checkbox" class="s"  name="" id="" value="" /></td>
				<td>Data</td>
				<td>Data</td>
				<td>Data</td>
			</tr>
			<tr>
				 
				<td><input type="checkbox"  class="s" name="" id="" value="" /></td>
				<td>Data</td>
				<td>Data</td>
				<td>Data</td>
			</tr>
		</table>
	</body>
	<script type="text/javascript" src="js/jquery-3.1.1.js"></script>
	<script type="text/javascript">
		$(".f").click(function(){
			$(".s").prop("checked",this.checked)
		})
	</script>
</html>

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>动画效果</title>
		<style type="text/css">
			div{
				width: 300px;
				height: 300px;
				background-color:  #FF1493;
				margin: 10px;
			}
		</style>
	</head>
	<body>
		<div id="div1">
			
		</div>
		<div id="div2">
			
		</div>
	</body>
	<script type="text/javascript" src="js/jquery-3.1.1.js"></script>
	<script type="text/javascript">
		$(document).click(function(){
			//toggle实现显示与消失的切换
			$("div").toggle(2000);
			//fadeToggle淡入淡出的切换
			$("div").fadeToggle(2000);
			//slideToggle上卷下拉的切换
			$("div").slideToggle(2000);
			
		})
	</script>
</html>

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>定时循环</title>
		<style type="text/css">
			img{
				width: 100%;
				height: 1400px;
			}
		</style>
	</head>
	<body>
		<img src="img/1001881.jpg"/>
		
	</body>
	<script type="text/javascript" src="js/jquery-3.1.1.js">	</script>
	<script type="text/javascript">
		setInterval(function(){
			$("img").toggle(500)
			$("img").fadeToggle(500)
			$("img").slideToggle(500)
		},2000)
	</script>
</html>

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>省市联动</title>
	</head>
	<body>
		<select name="pro" id="pro">
			<option value="">---请选择---</option>
		</select>
		<select name="city" id="city">
			<option value="">---请选择---</option>
		</select>
	</body>
	<script type="text/javascript" src="js/jquery-3.1.1.js"></script>
	<script type="text/javascript">
		var pros = ["河北省","河南省","陕西省","福建省","陕西省"];
		var citys = [
		["石家庄","保定","邯郸","唐山","秦皇岛"],
		["洛阳","南阳","信仰","濮阳","安阳"],
		["大同","临汾","太原","阳泉","运城"],
		["福州","莆田","厦门","武夷山","三明"],
		["济南", "青岛", "淄博", "滨州", "德州"]
		];
		
		//遍历省份数组
		$(pros).each(function(index,ele){
			$("#pro").append($("<option value='"+ index+"'>"+ele+"</option>"));
		})
		//当省下拉框发生值改变时间时,给市级下拉框添加元素
		$("#pro").change(function(){
			//先清空一次市级下拉框
			$("#city Option").remove(":gt(0)");
			//找到省对应的市数组
			var cs = citys[$(this).val()];
			$(cs).each(function(index,ele){
				$("#city").append($("<option value='"+index +"'>" +ele+ "</option>"))
				
			})
		})
		
		
	</script>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值