例子,js不采用reverse函数实现字符串反转。
复制代码 代码示例:
<html>
<head>
<title>字符串反转_www.jb200.com</title>
<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>
</head>
<body>
<table>
<tr>
<td><input type="textfield" id="input"/>=></td>
<td><div id="result"></div></td>
</tr>
</table>
<input type="button" value="reverse" onclick="reverse()"/>
</body>
</html>
JavaScript reverse() 方法
创建一个数组,然后颠倒其元素的顺序:
复制代码 代码示例:
<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>
输出结果:
George,John,Thomas
Thomas,John,George