动态加载iframe时get请求传递中文参数乱码解决方法
时间:2021-03-26 09:22:21|栏目:JavaScript代码|点击: 次
当用户的页面需要动态加载iframe 时,
如果iframe的src中包传中文参数会出现编码错误;必须加编码,然后再解码。
编码:encodeURI(encodeURI("包含中文的串"))
解码:java.net.URLDecoder.decode("需要解码的串","utf-8");
解决方案
使用 encodeURI('中文') 进行编码操作,
js代码:
$(function() {
$('#frame').attr('src', '${basePath}mi/right.do?bidItemName=' +encodeURI('中文'));
});
html代码
<html>
<body>
<iframe src="" scrolling="no" frameBorder=0 id="frame"></iframe>
</body>
</html>
如果iframe的src中包传中文参数会出现编码错误;必须加编码,然后再解码。
编码:encodeURI(encodeURI("包含中文的串"))
解码:java.net.URLDecoder.decode("需要解码的串","utf-8");
解决方案
使用 encodeURI('中文') 进行编码操作,
js代码:
复制代码 代码如下:
$(function() {
$('#frame').attr('src', '${basePath}mi/right.do?bidItemName=' +encodeURI('中文'));
});
html代码
复制代码 代码如下:
<html>
<body>
<iframe src="" scrolling="no" frameBorder=0 id="frame"></iframe>
</body>
</html>
栏 目:JavaScript代码
下一篇:密码强度检测效果实现原理与代码
本文标题:动态加载iframe时get请求传递中文参数乱码解决方法
本文地址:http://www.codeinn.net/misctech/88341.html






