日期:2014-05-16  浏览次数:20822 次

关于decodeURIComponent无法使用
HTML code
<form action="tool.html" method = "get">
      查找您想要的应用
      <input name="searchFor" type="text" size="10" />
      <input name="goButton" type="submit" value="搜索" />
    </form>


我把这个get的值传到这个静态页面, 但是中文都是乱码 论坛上的大神说用decodeURIComponent这个方法进行解码。 不过我用了IE说是无效字符, 请求大神帮助。 别的方法也可以
HTML code
var qs = window.location.search.substring(1);
var ar = qs.split('&');
var tmp = ar[0].split('=');
var str = decodeURI(tmp[1]);


------解决方案--------------------
JScript code
//IE下执行下面这样代码会报错?不可能吧!
alert(decodeURIComponent('%E6%B5%8B%E8%AF%95'));

------解决方案--------------------
是的。你可以试一下。如果是gbk编码,你需要把经 encodeURIComponent() 编码后的值传递过去。那边才可以decodeURIComponent 解码。