<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1"/> <link rel="stylesheet" type="text/css" href="css/bootstrap.css"/> </head> <body> <nav class="navbar navbar-default"> <div class="container-fluid"> </div> </nav> <div class="col-md-6 well"> <hr style="border-top:1px dotted #ccc;"/> <div class="col-md-5"> <br /> </div> </div> </body> </html>
displayItem(); function displayItem(){ var arr = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]; var html = ""; for(var i=0; i<arr.length; i++){ html += "<div width='200' height='200' style='border:1px solid #000; padding:10px; margin:10px; font-size:50px; float:left;'>"+arr[i]+"</div>"; } html += "<br style='clear:both;'/>"; document.getElementById('result').innerHTML = html; } function arrOrder(){ var arr = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]; var html = ""; arrayRear(arr).forEach(function(item){ html += "<div width='200' height='200' style='border:1px solid #000; padding:10px; margin:10px; font-size:50px; float:left;'>"+item+"</div>"; }) html += "<br style='clear:both;'/>"; document.getElementById('result').innerHTML = html; } function arrayRear(arr) { for (var i = 0, rear = [], randomIndex = 0; i < arr.length; i++) { randomIndex = Math.floor(Math.random() * arr.length); while (rear.indexOf(arr[randomIndex]) !== -1) { randomIndex = Math.floor(Math.random() * arr.length); } rear.push(arr[randomIndex]); } return rear; }