JavaScript中的encodeURIComponent()函数
该decodeURIComponent()函数接受一个表示编码的URI(统一资源标识符)的字符串值,对该字符串值进行解码并返回结果。
语法
它的语法如下
encodeURIComponent('http://www.qries.com/');示例
<html>
<head>
<title>JavaScript Example</title>
</head>
<body>
<script type="text/javascript">
var encodedData = encodeURIComponent('http://www.qries.com/?x=шеллы');
document.write("Encoded Data: "+encodedData);
document.write("<br>");
var decodedData = decodeURIComponent(encodedData);
document.write("Decoded Data: "+decodedData);
</script>
</body>
</html>输出结果
Encoded Data: http%3A%2F%2Fwww.qries.com%2F%3Fx%3D%D1%88%D0%B5%D0%BB%D0%BB%D1%8B Decoded Data: http://www.qries.com/?x=шеллы