jQuery的排他思想,隐式迭代案例,不需要采用双重for循环 ,这个是一个很好的操作思想,可以让我们的代码简洁,大家可以多理解一下一个思想并且操作实例
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>隐式迭代</title>
<script src="jquery.min.js"></script>
<!-- 样式 -->
<style>
* {
margin: 0;
padding: 0;
}
li {
list-style-type: none;
}
a {
text-decoration: none;
font-size: 14px;
}
.nav {
margin: 100px;
}
.nav>li {
position: relative;
float: left;
width: 80px;
height: 41px;
text-align: center;
}
.nav li a {
display: block;
width: 100%;
height: 100%;
line-height: 41px;
color: #333;
}
.nav>li>a:hover {
background-color: #eee;
}
.nav ul {
display: none;
position: absolute;
top: 41px;
left: 0;
width: 100%;
border-left: 1px solid #FECC5B;
border-right: 1px solid #FECC5B;
}
.nav ul li {
border-bottom: 1px solid #FECC5B;
}
.nav ul li a:hover {
background-color: #FFF5DA;
}
</style>
</head>
<body>
<button>快速</button>
<button>快速</button>
<button>快速</button>
<button>快速</button>
<button>快速</button>
<button>快速</button>
<button>快速</button>
<script>
// js 操作文件
$(function(){
// 1. 隐式迭代 给所有的按钮都绑定了点击事件
$('button').click(function(){
// 2. 当前的元素变化背景颜色
$(this).css('background' , 'purple') ;
// 3.其他的隐式迭代
$(this).siblings('button').css('background' , '');
})
})
</script>
</body>
</html>