我有两个类似的 HTML 块(一个用于新闻,第二个用于特价),它们的底部都有分页按钮,所以我尝试构建一个通用功能来独立更改每个块的分页按钮状态(活动/非活动),但我失败了。这就是问题所在。我该怎么做?
这是 JSFiddle:http: //jsfiddle.net/iamsvyat/5TjKQ/
HTML:
<div id="news-block">News Block</div>
<div class="pag-circles">
<button class="pag-circle-1 active"> </button>
<button class="pag-circle-2 inactive"> </button>
<button class="pag-circle-3 inactive"> </button>
<button class="pag-circle-4 inactive"> </button>
</div>
<div id="special-offers-block">Special Offers Block</div>
<div class="pag-circles">
<button class="pag-circle-1 active"> </button>
<button class="pag-circle-2 inactive"> </button>
<button class="pag-circle-3 inactive"> </button>
<button class="pag-circle-4 inactive"> </button>
</div>
CSS:
button {
width: 0;
height: 0;
margin: 0;
padding: 0;
border: 6px solid black;
border-radius: 6px;
}
.active {
border-color: red;
}
.inactive {
border-color: black;
}
button:focus {
outline: none;
}
button:active {
position: relative;
top: 1px;
}
jQuery:
$("#news-block").next(".pag-circles").children().click(function() {
//if the first button is clicked
//if the second button is clicked
//if the third button is clicked
//if the fourth button is clicked
});
$("#special-offers-block").next(".pag-circles").children().click(function() {
//if the first button is clicked
//if the second button is clicked
//if the third button is clicked
//if the fourth button is clicked
});