zoukankan      html  css  js  c++  java
  • window.location.search的用法 和 地址栏的的javsscript编码与解码

    ocation.search是从当前URL的?号开始的字符串 
    如:http://www.51js.com/viewthread.php?tid=22720 

    它的search就是?tid=22720 

    eg:

    function getQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
        var r = window.location.search.substr(1).match(reg);
        if (r)
            return decodeURIComponent(r[2]);
    }

    JavaScript decodeURIComponent() 函数

    定义和用法

    decodeURIComponent() 函数可对 encodeURIComponent() 函数编码的 URI 进行解码。

    实例

    在本例中,我们将使用 decodeURIComponent() 对编码后的 URI 进行解码:

    <script type="text/javascript">
    
    var test1="http://www.w3school.com.cn/My first/"
    
    document.write(encodeURIComponent(test1)+ "<br />")
    document.write(decodeURIComponent(test1))
    
    </script>

    输出:

    http%3A%2F%2Fwww.w3school.com.cn%2FMy%20first%2F
    http://www.w3school.com.cn/My first/

    参考:

    http://shirlly.iteye.com/blog/385361

    http://www.w3school.com.cn/jsref/jsref_decodeURIComponent.asp

  • 相关阅读:
    Redis 多项目序列化问题
    Java序列化的相关认知
    《Proxy系列专题》:代理模式(静态、JDK、CGLib)
    好文章地址
    @ServletComponentScan
    Spring 自动配置的原理
    B+Tree
    Sentinel
    ThreadPoolUtil
    UUID
  • 原文地址:https://www.cnblogs.com/qqhfeng/p/10552533.html
Copyright © 2011-2022 走看看