本帖最后由 zj3701838 于 2009-12-23 18:27:55 编辑

解决方案 »

  1.   


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>New Document</title>
    <script type="text/javascript">
    <!--
    window.onload = function(){
    var array = ["a","b","c","d","e","f","g"];
    for(var i = 0,len = array.length; i < len; i++){
    var index = Math.round((array.length-1) * Math.random());//得到数组长度范围内的整数
    document.write(array[index]);
    array.splice(index,1);//删除index位置的元素,只删一个
    }
    document.write("<br>");
    document.write("length:" + array.length);//最后的数组长度为零了
    }
    //-->
    </script>
    </head>
    <body></body>
    </html>
    楼主试试吧,量身定做!花了俺二十分钟!!
      

  2.   

    在原来的基础上改一下
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 
    <html> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> 
    <title>New Document </title> 
    <script type="text/javascript"> 
    <!--
         var _array = ["a", "b", "c", "d", "e", "f", "g"];
         function getValue() {
             if (_array.length == 0) {
                 alert("Array length is zero!");
                 return;
             }         var result = document.getElementById('result'),
                     index = Math.round((_array.length - 1) * Math.random()); //得到数组长度范围内的整数
             result.innerText += (result.innerText == '' ? '' : ',') + _array[index];
             _array.splice(index, 1); //删除index位置的元素,只删一个 
         } 
    //--> 
    </script> 
    </head> 
    <body> 
        <div id="result"></div>
        <input type="button" value="GetValue" onclick="getValue()" />
    </body> 
    </html>