JavaScript練習題目(2)文字域內的字串反轉

鍾超發表於2011-11-15
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>My First Script</title>
<script type="text/javascript">
function test() {
	var text_string = document.getElementById("input_text").value;
	var result = text_string.split("").reverse().join("");
	document.getElementById("result").innerHTML = result;
}
</script>
</head>
<body>
<form>
	<label>輸入</label><input id="input_text" type="text" value="預設值" />
	<input type="button" value="設定為'哈哈'" onclick="test();" />
	<div id="result"></div>
</form>
</body>
</html>

相關文章