$('#selsort').change(function(){
if ($(this).val() == 'asc') {/*sort abc by date asc;*/}
else {/*sort abc by date desc;*/}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class='abc' data-date='21.09.2018'>lorem 1</div>
<div class='abc' data-date='22.09.2018'>lorem 2</div>
<div class='abc' data-date='23.09.2018'>lorem 3</div>
<select id='selsort'>
<option value='asc'>ASC</option>
<option value='desc'>DESC</option>
</select>
如何按abc
中的日期对date-date
div进行排序?
lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum
答案 0 :(得分:0)
您可以使用以下内容:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div data-wrapper>
<div class='abc' data-date='21.09.2018'>lorem 1</div>
<div class='abc' data-date='22.09.2018'>lorem 2</div>
<div class='abc' data-date='23.09.2018'>lorem 3</div>
</div>
<select id='selsort'>
<option value='asc'>ASC</option>
<option value='desc'>DESC</option>
</select>
sort
注意:jQuery的Array.sort
方法显然只供内部使用。您可以轻松地将选择内容转换为数组,并在需要时使用{{1}}本身(jQuery的版本是它的代理,但我想将来可能会消失)。