惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

腾讯CDC
aimingoo的专栏
aimingoo的专栏
S
SegmentFault 最新的问题
A
About on SuperTechFans
Engineering at Meta
Engineering at Meta
宝玉的分享
宝玉的分享
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 叶小钗
WordPress大学
WordPress大学
N
Netflix TechBlog - Medium
MyScale Blog
MyScale Blog
Stack Overflow Blog
Stack Overflow Blog
Microsoft Azure Blog
Microsoft Azure Blog
博客园 - 聂微东
M
MIT News - Artificial intelligence
F
Fortinet All Blogs
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Blog — PlanetScale
Blog — PlanetScale
T
Tailwind CSS Blog
Recent Announcements
Recent Announcements
Jina AI
Jina AI
大猫的无限游戏
大猫的无限游戏
Apple Machine Learning Research
Apple Machine Learning Research
J
Java Code Geeks

博客园 - 清雨轩

用dom生成html文件.的常见问题 div+css制作企业网站经验收集 appendNode? 可以直接一个节点树 - 清雨轩 - 博客园 php(alexa排名查询) 下拉菜单 美工版(不用写代码) CSS学习随笔 windows2003 ftp及相关权限 php出现Unable to load dynamic library 'c:\php\extensions\php_mssql.dll' - 清雨轩 win2003的服务器配置. 关于引用,还是按值. 开发时会遇到..注意 个人javascript作品集 事件监听是可吃CPU的事情。以后还是不用事件监听 用正则改变字符串的处理速度。 faq:responseXML has no properties in firefox or responseXML is null 正则表达式 不允许为空 下拉头像菜单 表单检测函数 [原创]使用js+xml制作的IE和FF都支持的树型菜单(程序不到4k哦) 个人觉得比较经典的菜单(来源:kijiji.cn)
[转载]纯js解决小偷的乱码.(强)
清雨轩 · 2006-09-18 · via 博客园 - 清雨轩

<script>
function encode_utf8(rawtext) {
   rawtext 
= rawtext.replace(/\r\n/g,"\n");
   
var utftext = "";
   
for(var n=0; n<rawtext.length; n++)
       
{
       
//
       var c=rawtext.charCodeAt(n);
       
// 0-127 => 1byte
       if (c<128)
           utftext 
+= String.fromCharCode(c);
       
// 127 - 2047 => 2byte
       else if((c>127&& (c<2048)) {
           utftext 
+= String.fromCharCode((c>>6)|192);
           utftext 
+= String.fromCharCode((c&63)|128);}

       
// 2048 - 66536 => 3byte
       else {
           utftext 
+= String.fromCharCode((c>>12)|224);
           utftext 
+= String.fromCharCode(((c>>6)&63)|128);
           utftext 
+= String.fromCharCode((c&63)|128);}

       }

   
return utftext;
}

function decode_utf8(utftext) {
   
var plaintext = ""var i=0var c=c1=c2=0;
   
while(i<utftext.length)
       
{
       c 
= utftext.charCodeAt(i);
       
if (c<128{
           plaintext 
+= String.fromCharCode(c);
           i
++;}

       
else if((c>191&& (c<224)) {
           c2 
= utftext.charCodeAt(i+1);
           plaintext 
+= String.fromCharCode(((c&31)<<6| (c2&63));
           i
+=2;}

       
else {
           c2 
= utftext.charCodeAt(i+1); c3 = utftext.charCodeAt(i+2);
           plaintext 
+= String.fromCharCode(((c&15)<<12| ((c2&63)<<6| (c3&63));
           i
+=3;}

       }

   
return plaintext;
}

</script>

posted on 2006-09-18 08:36  清雨轩  阅读(608)  评论(0)    收藏  举报

刷新页面返回顶部