JavaScript implements simple ordering of page elements (Ul-li)

Source: Internet
Author: User

JavaScript implements simple ordering of page elements (Ul-li)

HTML page:

<inputtype= "button"value= "Show"onclick= "Show ()" />    <ulID= "UL1">      <Li>4</Li>      <Li>3</Li>      <Li>2</Li>      <Li>1</Li>    </ul>

JavaScript code

functionShow () {varUl1=document.getelementbyid ("Ul1"); //find out all our Li drops.      varLis=ul1.getelementsbytagname ("Li"); //set up with a new array of drops Yes      varlist=[]; varlilen=lis.length;  for(vari=0;i<lilen;i++){         //This is what we add.list[i]=Lis[i]; }      //sort an array of dropsList.sort (function(li1,li2) {varn1=parseint (li1.innerhtml); varN2=parseint (li2.innerhtml); returnN1-N2;//so let's do our simple comparison drip      })            //and then we can appendchild our basic operation.       for(varj=0;j<lilen;j++) {ul1.appendchild (list[j]);//the array is already lined up in order to drip;         //some of them are very simple methods of dripping ah;         //How am I going to make a drip?      }  }

The same code that we can apply with the drop in our table sort

JavaScript implements simple ordering of page elements (Ul-li)

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.