代码之家  ›  专栏  ›  技术社区  ›  ansiart

取消隐藏/解码包含+的字符串

  •  2
  • ansiart  · 技术社区  · 14 年前

    我有一些html是由PHP的urlencode输出的-基本上是一组简单的锚,如下所示:

    <a href="#i+have+some+spaces">link1</a>
    

    unescape('Video+Games');    // returns Video+Games
    decodeURI('Video+Games');   // returns Video+Games
    decodeURIComponent('Video+Games');  // returns Video+Games
    
    1 回复  |  直到 14 年前
        1
  •  2
  •   user113716    14 年前

    我觉得你需要自己动手 .replace()

    href.replace(/\+/g, ' ');
    

    编辑: 我以为我有一个MDC文档指定了这一点,但我现在能找到的最接近的是这个注释。

    https://developer.mozilla.org/Talk:en/JavaScript/Reference/Global_Objects/decodeURIComponent

    我可能一直在想 MDC encodeURIComponent docs :