var str = "abcdef";
console.log( str.split("").reverse().join("") ); ');
//分解
var str="abcdefg";
var a=str.split(""); //先拆分成数组
var b=str.split("").reverse(); //再反转,但还是数组
var c=str.split("").reverse().join("");//最后把数组变成字符串
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<title>
javascript字符串反转 - www.jb200.com</title>
</head>
<body onkeyup="set(event);">
<span id=rword style="font-size:13px"></span>
<br />
<input id=sword value="" size=100 onkeyup="r(event);">
<br />
<span id=info style="font-size:13px">ctrl+enter开启和关闭实时反转,enter在关闭实施反转时进行反转,回车之后,内容自动复制到剪切板</span>
<script>
while(confirm("我是好人,对么?")!=true) 1;
word_buffer = "";
word_update = true;
function r(evt)
{
if (!word_update && evt.keyCode!=13)
{
return;
}
str = "";
word = (document.getElementById("sword")).value;
for (i=word.length-1; i>=0; i--)
{
str = str + word.charAt(i);
}
(document.getElementById("rword")).innerText = str;
window.clipboardData.setData('text',str);
word_buffer = str;
}
function set(evt)
{
if(evt.ctrlKey==true)
{
word_update = !word_update;
}
}
</script>
</body>
</html>