Implementation of Js,jquery sorting:
Important: The easiest way to achieve a sort is to
First read the tags in jquery into the object array
Sort the array of objects with JS (sort on an array of objects, do not try to directly change the content of the Web page directly)
Overwrites the array of labels on the Web page with the object array content;
Sort from text short to long
Copy Code code as follows:
Sort from text short to long
var arr_a=new Array ();
var i=0;
$ (". Type_list_txt > Span:contains (' t-shirts ')"). Parent (). Children ("a"). each (function () {
arr_a[i]=$ (This). Clone ();
i++;
});
for (i=0; i<arr_a.length;i++)
{
for (j=i+1;j<arr_a.length;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-shirts ')"). Parent (). Children ("a"). each (function () {
$ (this). ReplaceWith ($ (arr_a[i]));
i++;
});