代码之家  ›  专栏  ›  技术社区  ›  Derek Adair

Javascript等价于php的urldecode()

  •  34
  • Derek Adair  · 技术社区  · 14 年前

    我编写了一个定制的xml解析器及其对特殊字符的锁定。所以我很自然地把它们编码到我的数据库里。

    urldecode()

    有延期吗 jquery 或者javascript可以做到这一点?

    3 回复  |  直到 13 年前
        1
  •  94
  •   kennytm    14 年前

    你可以用 the decodeURIComponent function 将%xx转换为字符。但是,要转换 +

    function urldecode(url) {
      return decodeURIComponent(url.replace(/\+/g, ' '));
    }
    
        2
  •  12
  •   Adi Lester    12 年前

    看看这个

    function urldecode (str) {
      return decodeURIComponent((str + '').replace(/\+/g, '%20'));
    }
    
        3
  •  -1
  •   Conner devopensource    12 年前

    我想你需要 decodeURI