Code exercises (definition of two-dimensional arrays, string addition and subtraction, creation and binding of child elements, sorting algorithm)

Source: Internet
Author: User

<!   doctype>/** * GetData method * Read the list of ID source, get the city name and the city corresponding air quality * return an array, format see example in function*/functionGetData () {varSource=document.getelementsbytagname ("Li");varNumber=document.getelementsbytagname ("B"); varData=NewArray (7); for(vari=0;i<data.length;i++) {data[i]=NewArray (2);}; //Define a two-dimensional array in JavaScript varI=0; while(Source[i]) {data[i][0]=source[i].innertext.replace (Number[i].innertext, ""); //The addition and subtraction of strings to the Replace function data[i][1]=number[i].innertext;i++;}; returndata;}functionSortaqidata (data) {varJ=0, I; while(j<6) //Sort the two-dimensional array by one digit size {i=j+1; while(i<7){   if(data[j][1]<data[i][1])   {varTEMP=DATA[J];d ata[j]=data[i];d ata[i]=temp;} i++;}; J++;};returndata;}functionrender (data) {varI=0; while(i<data.length) {  varWrote=document.createelement ("Li"); i++; Wrote.innertext= "+i+" name "+data[i-1][0]+" "+data[i-1][1]; varResort=document.getelementbyid ("Resort");                                                              Resort.appendchild (wrote); //Note that you should create child elements and add content before binding the child elements of the Parent element}}functionBtnhandle () {varAqidata =GetData (); Aqidata=Sortaqidata (Aqidata); Render (Aqidata);}functioninit () {varButton=document.getelementbyid ("Sort-btn"); Button.addeventlistener ("Click", Btnhandle); //under this, bind a click event to SORT-BTN and trigger the Btnhandle function when clicked.}init ();</script></body>

Code exercises (definition of two-dimensional arrays, string addition and subtraction, creation and binding of child elements, sorting algorithm)

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.