javascript中的escape()和unescape()函数的使用方法

来源:互联网 发布:老男孩教育大数据 编辑:程序博客网 时间:2024/05/21 07:51

(一).示例图片效果

(二).代码
<html>
<head>
<title>escape()和unescape()函数的使用方法</title>
</head>
<body>
<script language="javascript">
function run()
{
alert("The esacpe value is:"+escape(document.form1.input1.value));
alert("The unesacpe value is:"+unescape(escape(document.form1.input1.value)));
}
</script>
<form name=form1>
<input type="text" name="input1" size=20 value="12320%456">
<input type=button name=click1 value="show escape value" onclick="run()">
</form>
</body>
</html>

 

escape 方法
对 String 对象编码以便它们能在所有计算机上可读,
escape(charString)
必选项 charstring 参数是要编码的任意 String 对象或文字。
说明
escape 方法返回一个包含了 charstring 内容的字符串值( Unicode 格式)。所有空格、标点、重音符号以及其他非 ASCII 字符都用 %xx

编码代替,其中 xx 等于表示该字符的十六进制数。例如,空格返回的是 "%20" 。

字符值大于 255 的以 %uxxxx 格式存储。
 
注意   escape 方法不能够用来对统一资源标示码 (URI) 进行编码。对其编码应使用 encodeURI 和encodeURIComponent 方法。

unescape 方法
解码用 escape 方法进行了编码的 String 对象。
unescape(charstring)
必选项 charstring 参数是要解码的 String 对象。
说明
unescape 方法返回一个包含 charstring 内容的字符串值。所有以 %xx 十六进制形式编码的字符都用 ASCII 字符集中等价的字符代替。
以 %uxxxx 格式(Unicode 字符)编码的字符用十六进制编码 xxxx 的 Unicode 字符代替.
注意   unescape 方法不能用于解码统一资源标识码 (URI)。解该码可使用 decodeURI 和 decodeURIComponent 方法。

原创粉丝点击