如何使用JQUERY订购div [英] How to order divs with JQUERY
问题描述
我有这样的div:
<div class="oferta SYB">
<div class="infoferta">
<div class="datosoferta">
<div class="ofertapagas">Pagás<br/> $ 67</div>
<div class="ofertavalor">Valor<br /> $ 160</div>
<div class="ofertadescuento">Descuento $ 93</div>
</div>
</div>
我想通过ofertapagas中的值来订购class =oferta的div或ofertavalor中的值或ofertadescuento中的值,我不知道如何,我不能使用数据库,我只能使用Jquery,我正在使用它的最后一个版本。
请帮忙!
i want to order the divs with the class="oferta" by the value in "ofertapagas" or the value in "ofertavalor" or the value in "ofertadescuento", i dont know how to, i cannot use the database, i just can use Jquery, i am using the last version of it. Some Help please!!
推荐答案
jQuery摘要 Array.prototype.sort
。由于jQuery wrappet集是 Array like objects ,你可以在它们上面调用 .sort()
或对它们进行排序。
jQuery abstracts Array.prototype.sort
. Since jQuery wrappet sets are Array like objects, you can just call .sort()
on them or apply sort on them.
var $datosoferta = $('.datosoferta');
$datosoferta.children().detach().sort(function(a,b) {
return +a.textContent.split(/\$/)[1].trim() - +b.textContent.split(/\$/)[1].trim();
}).appendTo($datosoferta);
参见 http://typeofnan.blogspot.com/2011/02/did-you-know.html
演示: http://jsfiddle.net/Rfsfs/
这篇关于如何使用JQUERY订购div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!