美文网首页
encodeURI() 函数

encodeURI() 函数

作者: 遥远不是北_ | 来源:发表于2018-09-28 10:46 被阅读7次

    定义和用法

    • encodeURI() 函数可把字符串作为 URI 进行编码。

    • 该方法不会对 ASCII 字母和数字进行编码,也不会对这些 ASCII 标点符号进行编码: - _ . ! ~ * ' ( ) 。

    • 该方法的目的是对 URI 进行完整的编码,因此对以下在 URI 中具有特殊含义的 ASCII 标点符号,encodeURI() 函数是不会进行转义的:;/?:@&=+$,#

    注意:
    • 如果 URI 组件中含有分隔符,比如 ? 和 #,则应当使用 encodeURIComponent() 方法分别对各组件进行编码。
    使用 encodeURI() 对 URI 进行编码:
    <script type="text/javascript">
    
    document.write(encodeURI("http://www.deer.com.cn")+ "<br />")
    document.write(encodeURI("http://www.deer.com.cn/My first/"))
    document.write(encodeURI(",/?:@&=+$#"))
    
    </script>
    

    输出结果:

    http://www.deer.com.cn
    http://www.deer.com.cn/My%20first/
    ,/?:@&=+$#
    

    相关文章

      网友评论

          本文标题:encodeURI() 函数

          本文链接:https://www.haomeiwen.com/subject/zrbuoftx.html