<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>菜鸟教程(runoob.com)</title>
<style>
.siblings *{
display: block;
border: 2px solid lightgrey;
color: lightgrey;
padding: 5px;
margin: 15px;
}
</style>
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
//JQuery中的 .prev()同级元素的前一个
//JQuery中的 .next()同级元素的后一个元素
$("li.element").prev("").css({"color":"red","border":"2px solid red"});
$("li").next(".element").css({"color":"red","border":"2px solid red"});
});
</script>
</head>
<body>
<div style="width:500px;" class="siblings">
<ul>
<li>我是第一个li标签</li>
<li>我是绿色的字体</li>
<li class="element">我是第三个li标签</li>
<li>我是红色的字体</li>
<li>我是第五个li标签</li>
</ul>
</div>
</body>
</html>
per() 和 next()
最新推荐文章于 2022-11-01 00:54:13 发布