Home  >  Article  >  Web Front-end  >  js, jQuery sorting implementation code, web page tag sorting implementation, tag sorting_javascript skills

js, jQuery sorting implementation code, web page tag sorting implementation, tag sorting_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:07:261006browse

Implementation of js, jQuery sorting:
Key points: To achieve sorting, the simplest way is to
first read the tags into the object array with jQuery
Use js to sort the object array (sort the object array, Do not try to make direct changes to the content of the web page)
Overwrite the tag array on the web page with the object array content;
//Sort from short text to long

Copy code The code is as follows:

//Sort from short text to long text
var arr_a=new Array();
var i=0;
$(".type_list_txt > span:contains('T-shirt')").parent().children("a").each(function(){
arr_a[i ]=$(this).clone();
i ;
});
for(i=0; i{
for(j= i 1;j{
if($(arr_a[i]).text().length > $(arr_a[j]).text().length )
{
temp=arr_a[i];
arr_a[i]=arr_a[j];
arr_a[j]=temp;
}
}
}
i=0;
$(".type_list_txt > span:contains('T-shirt')").parent().children("a").each(function(){
$(this ).replaceWith($(arr_a[i]));
i ;
});
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn