如何实现把<input name="ww" type="text" id="ww" value=""/>输入的中文转换成 IE地址栏%ab%cd%ef这样的编码存数据库中.希望大虾们赐教 如果可以希望做下标注 这样方便我学习谢谢 还有 如果存入数据库了 像<input name="ww" type="text" id="ww" value="<%=(w.Fields.Item("wd").Value)%>" />这样正常读取成中文

解决方案 »

  1.   

    我建议你还是不转换的好,需要的时候再转换。
    如果要转换,可以使用Server.UrlEncode等方法
      

  2.   

    输入escape(str)
    输出Server.UrlEncode(str)
      

  3.   


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <title>code.html</title>

        <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
        <meta http-equiv="description" content="this is my page">
        <meta http-equiv="content-type" content="text/html; charset=UTF-8">
        <script type="text/javascript">
         alert(encodeURIComponent("中国"));
    alert(escape(escape('小叮当')));
    alert("解码:" + unescape(unescape('%25u5F20')));
    alert("解码:" + unescape(decodeURIComponent('%25u5F20')));
    alert("解码:" + unescape(decodeURI('%25u5F20')));
    alert("转码:" + encodeURIComponent('小叮当'));
    alert("2转码:" + encodeURIComponent(encodeURIComponent('小叮当')));
    alert("转码:" + encodeURI('小叮当'));
    alert("2转码:" + encodeURI(encodeURI('小叮当')));
    alert("转码2:" + escape(encodeURIComponent('小叮当')));
    alert("转码2:" + escape(encodeURI('小叮当')));
    alert("转码3:" + escape(escape(encodeURI('小叮当'))));
    alert("转码3:" + escape(encodeURIComponent(encodeURIComponent('小叮当'))));
    alert("转码3:" + escape(encodeURI(encodeURI('小叮当'))));



    </script>
      </head>
      
      <body>
      </body>
    </html>
    转换后如果传入服务器,还需要在服务器端转回来
    URLencode