用JavaScript编码后如何解码字符串?
要编码 一个字符串,我们需要encodeURIComponent()或encodeURI(),对一个字符串进行解码, 我们需要decodeURIComponent()或decodeURI()。最初,我们使用过 escape()对字符串进行编码, 但是由于不建议使用它,因此我们现在使用encodeURI()。
语法1
encodeURIComponent(string);
语法2
decodeURIComponent(string);
示例
在下面的例子中,首先,一个字符串被取和编码 使用是encodeURI()和后解码用decodeURI()。稍后,编码 和解码 结果都显示在输出中。
<html>
<body>
<p id = "encoding"></p>
<script>
var str = "Tutorix is the best e-learning platform";
var enc = encodeURI(str);
var dec = decodeURI(enc);
var res = "After encoding: " + enc + "
</br>" + "After Decoding: " + dec;
document.getElementById("encoding").innerHTML = res;
</script>
</body>
</html>输出结果
After encoding: Tutorix%20is%20the%20best%20e-learning%20platform After Decoding: Tutorix is the best e-learning platform
热门推荐
3 祝福语简短的微信
10 幼儿祝福语大全简短贺卡
11 感谢教官文案祝福语简短
12 鼠年同事祝福语简短创意
13 元旦祝福语 简短独特群发
14 妈咪跟我生日祝福语简短
15 给儿子新婚祝福语简短
16 伴娘祝福语长文案简短
17 恭喜高考完祝福语简短
18 生日祝福语送老公简短