Javascript 版本utf-8转换为gb2312

function gb2312(key)
              {
                    var r = "";
                    for(var i=0;i<key.length;i++)
                    {
                            var t = key.charCodeAt(i);
                            if(t>=0x4e00 || t==0x300A || t==0x300B)
                            {
                                    try
                                    {
                                    execScript("ascCode=hex(asc(\""+key.charAt(i)+"\"))", "vbscript"); r += ascCode.replace(/(.{2})/g, "%$1"); }
                                    catch(e)
                                     {}
                             }
                            else{r += escape(key.charAt(i))}
                       }
                    return r;
               }


 

posted @ 2010-01-11 15:51  星火卓越  阅读(1015)  评论(0编辑  收藏  举报