zoukankan      html  css  js  c++  java
  • JS

    encodeURI(String)主要用于整个URI(例如,http://www.jxbh.cn/illegal value.htm),而encodeURIComponent(String)主要用于对URI中的某一段(例如前面URI中的value.htm)进行编码。它们的主要区别在于,encodeURI()不会对本身属于URI的特殊字符进行编码,例如冒号、正斜杠、问号和井字号;而encodeURIComponent()则会对它发现的任何非标准字符进行编码。来看下面的例子:

    <script type="text/javascript">  
      
    var test1="http://www.wljcz.com/My first/";  
    var nn=encodeURI(test1);  
    var now=decodeURI(test1);  
    document.write(nn+ "<br />");  
    document.write(now);  
      
    var test1="http://www.wljcz.com/My first/";  
    var bb=encodeURIComponent(test1);  
    var nnow=decodeURIComponent(bb);  
    document.write(bb+ "<br />");  
    document.write(nnow);  
    
    </script>

    其运行结果为:

    http://www.wljcz.com/My%20first/
    http://www.wljcz.com/My first/

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

  • 相关阅读:
    el-upload文件上传组件
    vue 自定义指令input表单的数据验证
    vue-resourse简单使用方法
    go语言基本运算符
    第4课
    第3课
    第2课
    第1课
    第0课
    第0课
  • 原文地址:https://www.cnblogs.com/andremao/p/7210259.html
Copyright © 2011-2022 走看看