Js的Url中传递中文参数乱码问题
2015-12-09 本文已影响0人
傻小子不会起名字
竟然经常遇到,但是每次都现找度娘,想想还是整理整理吧
geekwangc重点:encodeURI编码,decodeURI解码
传参页面JavaScript代码:
var url = “bad.html”;
var userName ="王超";
window.open(encodeURI(url + “?userName=” + userName)); }
接收参数页面:bad.html:
var urlinfo = window.location.href;//获取url
var userName = urlinfo.split(“?”)[1].split(“=”)[1];//拆分url得到”=”后面的参数
decodeURI(userName);