当前位置: 代码迷 >> 综合 >> javascript 实现页面间传值(3) 解决中文乱码问题
  详细解决方案

javascript 实现页面间传值(3) 解决中文乱码问题

热度:15   发布时间:2023-10-27 02:33:30.0

post.html :

<html>
<head><meta charset="GBK"/><title></title><script>function totest(){var parm1="你好";var myurl="read.html"+"?"+parm1;// encodeURI 编码window.location.assign(encodeURI(myurl));}</script>
</head>
<body><input type="button" value="post" onClick="totest()"/>
</body>
</html>

read.html :

<html>
<head><title></title><script>window.onload = function(){var url = decodeURI(window.location.search).slice(1);document.getElementById("read").innerHTML=url;};</script>
</head>
<body>
<div id="read"></div>
</body>
</html>


注: slice(1) 方法可以截取从第一个字符开始的字符串,否则得到的值的第一个字符会有一个 '?' 符号。

  相关解决方案