文字列エンコード・デコード(escape, unescape)
<html> <head> <title>文字列エンコード</title> <script language="JavaScript"> <!-- function change1() { // 文字列をエンコード document.form1.text2.value = escape(document.form1.text1.value); } function change2() { // エンコードされた文字列をデコード document.form2.text2.value = unescape(document.form2.text1.value); } //--> </script> </head> <body> <form action="" method="" name="form1"> 文字列をエンコード<br> <input type="text" name="text1" size="50"> <input type="button" value="変換" onClick="change1()"> <input type="text" name="text2" size="50"> </form> <br> <form action="" method="" name="form2"> エンコードされた文字列をデコード<br> <input type="text" name="text1" size="50"> <input type="button" value="変換" onClick="change2()"> <input type="text" name="text2" size="50"> </form> </body> </html>
〔 実行する 〕