Today, 51JS has posted this problem, the original thought is to the content alphabetically order, because the previous read a positive order of the article, I would like to reverse should not be difficult, looked at the data will quickly fix the problem.
<textarea id="runcode81434"><ptml> <pead> <title> Worry-free script code test page </title> </pead> <body> <select name= "a" I D= "A" > <option value= "b" >b</OPTION> <option value= "E" >e</OPTION> <option value= "C" >c</OPTION> <option value= "F" >f</OPTION> <option value= "a" >a</OPTION> </ select> <script type= "Text/javascript" > Function st (a,b) {if (a>b) return-1; else if (a<b) return 1; else return 0; function sort (id) {var s=document.getelementbyid (ID); if (!s) return; var t1=[],t2=[],tt=s.options; while (tt.length>0) {t1[t1.length]=tt[0].text; T2[t2.length]=tt[0].value; Tt.remove (0); } t1.sort (ST); for (Var i=0,c1,c2;c1=t1[i],c2=t2[i];i++) {Tt.add (new Option (C1,C2)); } sort ("a"); </script> </body> </ptml></textarea>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]
But look back after the original landlord no problem description Clearly, his intention is to list content in reverse order, that is, ABCEF into FECBA.
Beginning to think that the difficult solution, suddenly recalled that the array has a reverse () function (the array content in reverse order), the problem suddenly become very simple.
<textarea id="runcode73148"><ptml> <pead> <title> Worry-free script code test page </title> </pead> <body> <select name= "a" I D= "A" > <option value= "b" >b</OPTION> <option value= "E" >e</OPTION> <option value= "C" >c</OPTION> <option value= "F" >f</OPTION> <option value= "a" >a</OPTION> </ select> <script type= "Text/javascript" > function sort (id) {var s=document.getelementbyid (ID); if (!s) return; var t1=[],t2=[],tt=s.options; while (tt.length>0) {t1[t1.length]=tt[0].text; T2[t2.length]=tt[0].value; Tt.remove (0); } t1.reverse (); T2.reverse (); for (Var i=0,c1,c2;c1=t1[i],c2=t2[i];i++) {Tt.add (new Option (C1,C2)); } sort ("a"); </script> </body> </ptml></textarea>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]