Go: implementation of Js,jquery sorting, implementation of page label sorting, label sorting

Source: Internet
Author: User

Js,jquery the implementation of the Sort:

Important: the simplest way to achieve a sort is to

    1. First read the label into an array of objects with jquery
    2. Sort an array of objects with JS (sort on an array of objects, do not attempt to directly change the contents of the Page)
    3. Overwrites an array of labels on a Web page with Object array contents;  
//sort from short to long in text        varArr_a=NewArray (); varI=0; $(". type_list_txt > Span:contains (' T-shirt ')"). 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-shirt ')"). Parent (). children ("a"). each (function(){               $( this). replacewith ($ (arr_a[i])); I++; });

Original Address: http://www.cnblogs.com/henw/archive/2011/04/26/2029474.html

Referring to the original text, I wrote my own sort, the original text is a simple selection of sort, my is bubble sort.

functionDoorder () {//#orderCom为页面上的按钮    varType = $ ("#orderCom"). attr ("type"));    Console.log (type); varFlelems =NewArray (); varfi = 0; //GLOBALFL is a global variable and gets the elements individually$ ("#detail" +globalfl). Children (). each (function() {flelems[fi]= $( this). Clone (); Fi++;    }); if(type== "asc"){            //ASC Sort         for(vari=0;i<flelems.length-1;i++){             for(varj=0;j<flelems.length-i-1;j++){                if(parsefloat ($ (flelems[j]). attr (' cval ')) >parsefloat ($ (flelems[j+1]). attr (' cval ')))){                    varEle =flelems[j]; flelems[j]= Flelems[j+1]; Flelems[j+1] =ele; }            }        }        $("#orderCom"). attr ("type", "desc"); $("#orderCom"). text ("points ↓"); }Else{        //desc Sort         for(vari=0;i<flelems.length-1;i++){             for(varj=0;j<flelems.length-i-1;j++){                if(parsefloat ($ (flelems[j]). attr (' cval ')) <parsefloat ($ (flelems[j+1]). attr (' cval ')))){                    varEle =flelems[j]; flelems[j]= Flelems[j+1]; Flelems[j+1] =ele; }            }        }                $("#orderCom"). attr ("type", "asc"); $("#orderCom"). text ("points ↑"); } fi= 0; //write the sorted HTML$ ("#detail" +globalfl). Children (). each (function(){        $( this). replacewith ($ (flelems[fi])); Fi++; });}

Go: implementation of Js,jquery sorting, implementation of page label sorting, label sorting

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.