Home > Web Front-end > JS Tutorial > Two ways to convert js encoding between gb2312 and utf8_javascript skills

Two ways to convert js encoding between gb2312 and utf8_javascript skills

WBOY
Release: 2016-05-16 17:26:29
Original
2218 people have browsed it

方法一:

复制代码 代码如下:

function gb2utf8(data){
      var glbEncode = [];
      gb2utf8_data = data;
      execScript("gb2utf8_data = MidB(gb2utf8_data, 1)", "VBScript");
      var t=escape(gb2utf8_data).replace(/%u/g,"").replace(/(.{2})(.{2})/g,"%$2%$1").replace(/%([A-Z].)%(.{2})/g,"@$1$2");
      t=t.split("@");
      var i=0,j=t.length,k;
      while( i         k=t[i].substring(0,4);
         if(!glbEncode[k]) 
         {
            gb2utf8_char = eval("0x" k);
            execScript("gb2utf8_char = Chr(gb2utf8_char)", "VBScript");
            glbEncode[k]=escape(gb2utf8_char).substring(1,6);
         }
         t[i]=glbEncode[k] t[i].substring(4);
      }
      gb2utf8_data = gb2utf8_char = null;
      return unescape(t.join("%"));
 }
 

 使用时:xxx.innerHTML=gb2utf8(req.responseBody);
方法二:
复制代码 代码如下:


 

在java类中配合使用: (适用于ajax)
复制代码 代码如下:

String dwp = new String(request.getParameter("dwp").getBytes("ISO-8859-1"),"gbk") ;
String dwc = new String(request.getParameter("dwc").getBytes("ISO-8859-1"),"gbk") ;
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template