Home > Web Front-end > JS Tutorial > 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
Release: 2016-05-16 18:07:26
Original
1062 people have browsed it

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 ;
});
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template