1
我想檢查當前點擊的文本是否與頁面上的任何其他文本具有相同的數據,因爲下面的文本會放在頁面上兩次。一旦文本被點擊,它將添加一個類(這個位正在工作),並且如果它也具有與頁面上任何其他文本相同的數據,那麼該文本也將被賦予新類。如果當前文本數據=任何其他文本數據,然後...?
<span class="AJAXPagerSpan" data-num="6">6</span>
<span class="AJAXPagerSpan" data-num="12">12</span>
<span class="AJAXPagerSpan" data-num="24">24</span>
$(".AJAXPagerSpan").click(function() {
<%= this.ID %>_Pager.ChangeResultsPerPage($(this).html());
// Check if any of its siblings are part of the "highlightclass" and remove them from it
$(this).siblings().removeClass("highlightclass");
if ($(this).data() == $(this).siblings().data()) {
$(this).addClass("highlightclass");
};
// Add it to the highlightclass
$(this).addClass("highlightclass");
});
這似乎沒有工作:( –
沒有你的元素具有相同的數據。 – Barmar
它的工作原理,看到小提琴。 – Barmar