【发布时间】:2016-03-14 15:05:34
【问题描述】:
我有两个可以切换颜色的箭头(向上和向下)。这很好用,除了我有一些问题。
当再次单击箭头时,我希望颜色恢复到原来的颜色,但在我单击另一个箭头之前,它会保持更改后的颜色。
我对这些箭头进行循环,例如,如果我有两组箭头(两个向上和两个向下),当我操作一组箭头时,另一组又回到原来的状态。
即使已注销的用户单击箭头,颜色仍然会发生变化。
有人可以帮我实现上述目标吗?
这就是我现在拥有的。
<a href="/post/{{ post.slug }}/vote?is_up=1" class="vote">
<span class="glyphicon glyphicon-triangle-top col-md-12" aria-hidden="true"></span></a>
<br />
<span class="col-md-12" style="height:1px; font-family: 'Passion One', cursive; bottom:10px; padding-left:0.01em;
"><h4 id="vote_count_{{ post.slug }}">{{ post.get_vote_count }}</h4></span> <br>
<a href="/post/{{ post.slug }}/vote?is_up=0" class="vote">
<span class="glyphicon glyphicon-triangle-bottom col-md-12" aria-hidden="true"></span></a>
<script>
$(document).ready(function(){
$('.glyphicon').click(function(){
$('.glyphicon').css('color', '#333');
$(this).css('color', '#16A085');
});
});
</script>
【问题讨论】:
-
你能为此做一个小提琴吗?
-
您可以使用
.toggleClass()在点击时切换css类。api.jquery.com/toggleclass
标签: javascript jquery