<div class="htmlarea"> <textarea id="runcode68046"> <script language="javascript"> function reverse() { var str=document.getElementById("input").value; var a=str.split(''); var result=new Array(); while(a.length) { result.push(a.pop()); } document.getElementById("result").innerHTML=result.join(''); } </script> <title>javascript</title> <table> <tr> <td> <input type="textfield" id="input">=></td> <td><div id="result"></div></td> </tr> </table> <input type="button" value="reverse" onclick="reverse()"> </textarea><br><input onclick="runEx('runcode68046')" type="button" value="运行代码"> <input onclick="doCopy('runcode68046')" type="button" value="复制代码"> <input onclick="doSave(runcode68046)" type="button" value="保存代码">[Ctrl+A 全选 注:<a href="http://www.jb51.net/article/23421.htm" title="查看具体详情" target="_blank">如需引入外部Js需刷新才能执行</a>]</div> <br><strong>JavaScript reverse() 方法 <br></strong>在本例中,我们将创建一个数组,然后颠倒其元素的顺序: <br><div class="htmlarea"> <textarea id="runcode59760"> <script type="text/javascript"> var arr = new Array(3) arr[0] = "George" arr[1] = "John" arr[2] = "Thomas" document.write(arr + " ") document.write(arr.reverse()) </script> </textarea><br><input onclick="runEx('runcode59760')" type="button" value="运行代码"> <input onclick="doCopy('runcode59760')" type="button" value="复制代码"> <input onclick="doSave(runcode59760)" type="button" value="保存代码">[Ctrl+A 全选 注:<a href="http://www.jb51.net/article/23421.htm" title="查看具体详情" target="_blank">如需引入外部Js需刷新才能执行</a>]</div> <br>输出: <br><div class="codetitle"> <span><a style="CURSOR: pointer" data="37733" class="copybut" id="copybut37733" onclick="doCopy('code37733')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code37733"> <br>George,John,Thomas <br>Thomas,John,George <br> </div>