zoukankan      html  css  js  c++  java
  • 在asp中使用js的encodeURIComponent方法

    大家知道,在js里encodeURIComponent 方法是一个比较常用的编码方法,但因工作需要,在asp里需用到此方法,查了好多资料,没有很好的方法,最后用了下面这个方法,基本解决了问题。

    <%
    Function aspEncodeURIComponent(sStr)
        aspEncodeURIComponent = myEncodeURIComponent(sStr)
    %>
    <script language="javascript" type="text/javascript" runat="server">  
      function myEncodeURIComponent(sStr){  
          return encodeURIComponent(sStr);  
      }  
    </script>
    <%
    End Function
    %>

    附注:

    encodeURIComponent 方法

    将文本字符串编码为一个统一资源标识符 (URI) 的一个有效组件。

    encodeURIComponent(encodedURIString)

    必选的 encodedURIString 参数代表一个已编码的 URI 组件。

    说明

    encodeURIComponent 方法返回一个已编码的 URI。如果您将编码结果传递给 decodeURIComponent,那么将返回初始的字符串。因为 encodeURIComponent 方法对所有的字符编码,请注意,如果该字符串代表一个路径,例如 /folder1/folder2/default.html,其中的斜杠也将被编码。这样一来,当该编码结果被作为请求发送到 web 服务器时将是无效的。如果字符串中包含不止一个 URI 组件,请使用 encodeURI 方法进行编码。

  • 相关阅读:
    第四季-专题8-Linux系统调用
    第四季-专题7-Linux内核链表
    Python3 运算符
    Python2和Python3有什么区别?
    python常见的PEP8规范
    机器码和字节码
    域名是什么?为什么域名是www开头?
    selenium自动化登录qq邮箱
    xpath+selenium工具爬取腾讯招聘全球岗位需求
    ArrayList
  • 原文地址:https://www.cnblogs.com/Spring/p/848642.html
Copyright © 2011-2022 走看看