<div class="htmlarea"> <textarea id="runcode96003"> <title>JavaScript生成随机数并自动排序</title> <script> var baseNum=[]; for(var i= 0;i<100;i++){ random = Math.floor(Math.random()*i); baseNum.push(random); } Array.prototype.cleanSort = function(){ var clean = []; this.sort(function(a,b){return a-b;}); for(var i=0;i<this.length;i++){ if(this[i]==this[i+1]){ continue; }else{ clean.push(this[i]); } } return clean; } document.write(baseNum.cleanSort().join('<br>')); </script> </textarea><br><input onclick="runEx('runcode96003')" type="button" value="运行代码"> <input onclick="doCopy('runcode96003')" type="button" value="复制代码"> <input onclick="doSave(runcode96003)" type="button" value="保存代码">[Ctrl+A 全选 注:<a href="http://www.jb51.net/article/23421.htm" title="查看具体详情" target="_blank">如需引入外部Js需刷新才能执行</a>]</div>