这是您问题的实际答案,尽可能准确 - 我怀疑您想将 DATE 包装在 I
演示
$(function() {
$('#review_sort_section a[data-uid="date"]')
.addClass("i-wrap ig-wrap-common i-sort-descend-common-wrap ig-wrap-common-r selected")
.html('<i class="i ig-common i-sort-descend-common">Date</i>');
});
结果:
<div id="review_sort_section" class="ieSucks">Sort by:
<a href="#" data-uid="date" class="i-wrap ig-wrap-common i-sort-descend-common-wrap ig-wrap-common-r selected"><i class="i ig-common i-sort-descend-common">Date</i></a>
<a href="#" data-uid="rating">Rating</a>
<a href="#" data-uid="vote">Vote</a>
</div>
假设 - 你可能想要这个代码:
HTML:
<div id="review_sort_section" class="ieSucks">Sort by:
<a href="#" data-uid="Date">Date</a>
<a href="#" data-uid="Rating">Rating</a>
<a href="#" data-uid="Vote">Vote</a>
</div>
jQuery:
演示
$(function() {
$("#review_sort_section a").on("click",function(e) {
e.preventDefault();
$(this).addClass("i-wrap ig-wrap-common i-sort-descend-common-wrap ig-wrap-common-r selected")
.html('<i class="i ig-common i-sort-descend-common">'+$(this).data("uid")+'</i>')
.siblings().each(function() {
$(this).html($(this).data("uid")).removeClass(); // siblings $(this)
});
// here we call the ajax to load the sorted data
});
});