1. [代码] 定义 var arr = [],tmp;var createRandom = function (num) { arr.indexOf(tmp = parseInt(Math.random() * num)) arr.push(tmp); num != arr.length createRandom(num);} 2. [代码] 调用 $(function () { createRandom(100); console.log(
1. [代码]定义
var arr = [],tmp; var createRandom = function (num) { arr.indexOf(tmp = parseInt(Math.random() * num)) && arr.push(tmp); num != arr.length && createRandom(num); }
2. [代码]调用
$(function () { createRandom(100); console.log(arr); });