这就是我想要实现的 -
相对于“深层内部产品 3”,定位“深层内部产品 2”和“深层内部产品 4”,并将上面的颜色涂成蓝色,下面的颜色用蓝绿色。
下面的代码工作正常,但是我想一次性定位 prev 和 next 而不是单独定位它,让我知道如何在单行代码中实现这一点。
var chain = $('ul.initial-list').find('ul').eq(1).find('li').eq(2);
chain.prev().addClass('prev');
chain.next().addClass('next');
我的代码 -
<!DOCTYPE html>
<html>
<head>
<title>Day 3 - 2</title>
<style>
p { font:14px Arial bold;}
.initial-list {font-size: 18px;}
li {color:red;}
.prev {color: blue;}
.next {color: teal;}
</style>
</head>
<body>
<p>Target "Deep Inner Product 2" & "Deep Inner Product 4" relative to "Deep Inner Product 3" and color upper one with blue and lower with teal.</p>
<ul class="initial-list">
<li>Product 1</li>
<li>Product 2</li>
<li>Product 3</li>
<li>Product 4</li>
<li>Product 5</li>
<ul>
<li>Inner Product 1</li>
<li>Inner Product 2</li>
<li>Inner Product 3</li>
<ul>
<li>Deep Inner Product 1</li>
<li>Deep Inner Product 2</li>
<li>Deep Inner Product 3</li>
<li>Deep Inner Product 4</li>
</ul>
<li>Inner Product 4</li>
<li>Inner Product 5</li>
</ul>
<li>Product 6</li>
<li>Product 7</li>
<li>Product 8</li>
</ul>
<script src="jquery.js"></script>
<script>
var chain = $('ul.initial-list').find('ul').eq(1).find('li').eq(2);
chain.prev().addClass('prev');
chain.next().addClass('next');
</script>
</body>
</html>