JavaScript table random sort code _javascript Tips

Source: Internet
Author: User
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <ptml xmlns=" http://www.w3.org/1999/xhtml "> <pead> <meta http-equiv=" Content-type "content=" text/html; charset=gb2312 "/> <title> table random sort exercise by Ahanan </title> <style type=" Text/css "> #main {width:700px; } #main div{width:200px; margin-left:10px; margin-top:20px; Float:left; } div table{width:100%; } </style> <script type= "Text/javascript" charset= "GB2312" > Function Arrrand (obj) {var a = new Array (); for (var i = 0;i < obj;i++) {A[i] = i + 1; } a.sort (function () {return 0.5-math.random ()}); return A; function randtable () {var c = Arrrand (len); for (var k = 0;k < Len;k + +) {Divs[c[k]-1].innerhtml = b[k]; } var b = new Array (); var divs = new Object; var Len;; Window.onload = function () {divs = document.getElementById ("main"). getElementsByTagName ("div"); Len = Divs.leNgth; for (var j = 0;j < len;j++) {b[j] = divs[j].innerhtml; } randtable (); } </script> </pead> <body> <div id= "main" > <div> <table border= "1" > <tr>& lt;td>a</td></tr> </table> </div> <div> <table border= "1" > &LT;TR&GT;&LT;TD&G T b</td></tr> </table> </div> <div> <table border= "1" > <tr><td>c</t d></tr> </table> </div> <div> <table border= "1" > &LT;TR&GT;&LT;TD&GT;D&LT;/TD&GT;&L t;/tr> </table> </div> <div> <table border= "1" > &LT;TR&GT;&LT;TD&GT;E&LT;/TD&GT;&LT;/TR&G T </table> </div> <div> <table border= "1" > <tr><td>F</td></tr> </ta ble> </div> </div> <input type= "button" onclick= "Randtable ()" value= "random Sort" > cloud-dwelling Community </body> </ptml>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

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.