我正在尝试按内容日期排序div...我已经实现了排序,但不是按日期排序...
HTML
HTML
<div id="all_elements">
<!-- one element -->
<div class="element">
<div class="display-number">02</div>
<div class="year">20-10-2011</div>
</div><!-- element -->
<!-- one element -->
<div class="element">
<div class="display-number">03</div>
<div class="year">22-09-2011</div>
</div><!-- element -->
<!-- one element -->
<div class="element">
<div class="display-number">01</div>
<div class="year">01-12-2011</div>
</div><!-- element -->
<!-- one element -->
<div class="element">
<div class="display-number">04</div>
<div class="year">01-06-2011</div>
</div><!-- element -->
<!-- one element -->
<div class="element">
<div class="display-number">05</div>
<div class="year">01-06-2010</div>
</div><!-- element -->
</div> <!--all_elements-->
JQUERY
<script>
function sortDescending(a, b) {
return $(a).find(".year").text() < $(b).find(".year").text() ? 1 : -1;
};
$(document).ready(function() {
$('#all_elements .element').sort(sortDescending).appendTo('#all_elements');
});
</script>
我知道我需要一个函数来确定内容是否为日期,只是不知道怎么做...
谁能帮帮我?