向上和向下箭头onclick

时间:2017-06-09 10:08:57

标签: javascript jquery html

我为按钮创建了HTML和css,我需要根据点击进行向上和向下箭头切换。我对HTML和CSS很好,但是使用jQuery不是很好。谁能让我开始这个? 点击.js-custom-sleeve-option箭头应该向上/向下更改。

.js-custom-sleeve-option {
    width: auto;
    min-width: 3.8rem;
    height: 3rem;
    display: inline-block;
    border: 1px solid #d1cac5;
    background: #f7f7f7;
    margin-right: 0.5rem;
    margin-bottom: 0.5rem;
    text-align: center;
}

.js-arrow-down {
    display: inline-block;
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 6px solid #233354;
    position: relative;
    left: 7px;
}

.js-arrow-up {
    display: inline-block;
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-bottom: 6px solid #233354;
    position: relative;
    left: 6px;
    bottom: 12px;
}
<div>
			<a class="js-custom-sleeve-option">
				<span class="js-arrow-down"></span>
			</a>
</div>

2 个答案:

答案 0 :(得分:0)

这将是这样的..当然你必须根据你的需要修改它

$(function(){
$(".js-custom-sleeve-option").on('click' , function(){
  this.find('span').removeClass('js-arrow-down').end().addClass('js-arrow-up');
});
});

答案 1 :(得分:0)

你可以使用jquery函数的toggleClass()

&#13;
&#13;
$('.js-custom-sleeve-option').click(function(){
$(this).children('span').toggleClass('js-arrow-down js-arrow-up')
})
&#13;
.js-custom-sleeve-option {
    width: auto;
    min-width: 3.8rem;
    height: 3rem;
    display: inline-block;
    border: 1px solid #d1cac5;
    background: #f7f7f7;
    margin-right: 0.5rem;
    margin-bottom: 0.5rem;
    text-align: center;
}

.js-arrow-down {
    display: inline-block;
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 6px solid #233354;
    position: relative;
    left: 7px;
}

.js-arrow-up {
    display: inline-block;
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-bottom: 6px solid #233354;
    position: relative;
    left: 6px;
    bottom: 12px;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
			<a class="js-custom-sleeve-option">
				<span class="js-arrow-down"></span>
			</a>
</div>
&#13;
&#13;
&#13;