开关按钮切换

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<style>
			*{
				padding: 0;
				margin: 0;
			}
			#hd{
				overflow: hidden;
				margin: 100px 300px;
				 100px;
			}
			#hd li{
				list-style: none;
				 50px;
				height: 30px;
				line-height: 30px;
				font-size: 13px;
				text-align: center;
				float: left;
				background: #eee;
			}
			#hd li.cur{
				background: deepskyblue;
				color: #fff;
			}
		</style>
		<script src="../1.10.2.jquery.min.js"></script>
	</head>
	<body>
		<ul id="hd">
			<li class="cur">开</li>
			<li>关</li>
		</ul>
	</body>
	<script>
		$("#hd li").click(function(){
//			方法一:
//			$(this).addClass('cur').siblings().removeClass('cur');
//			方法二:
			$("#hd li").toggleClass('cur');
		})
	</script>
</html>
原文地址:https://www.cnblogs.com/gxywb/p/9429948.html