社区
JavaScript
帖子详情
急急 动态JS 调用文本 乱码
yfgcq
2007-04-13 08:59:22
动态生成JS document.createElement('script');SRC="xx.txt"调用静态文本
以前是使用ASP FSO生成的静态文本.txt
现在该用了NET生成的静态文本(.txt)(UTF8)
但是现在src="xx.txt"的时候,怎么成了乱码?
调用脚本的页面编码GB2312
是不是在调用的时候,要把.txt转换成GB2312?
如果要转的话 ,怎么转啊?
...全文
401
6
打赏
收藏
急急 动态JS 调用文本 乱码
动态生成JS document.createElement('script');SRC="xx.txt"调用静态文本 以前是使用ASP FSO生成的静态文本.txt 现在该用了NET生成的静态文本(.txt)(UTF8) 但是现在src="xx.txt"的时候,怎么成了乱码? 调用脚本的页面编码GB2312 是不是在调用的时候,要把.txt转换成GB2312? 如果要转的话 ,怎么转啊?
复制链接
扫一扫
分享
转发到动态
举报
AI
作业
写回复
配置赞助广告
用AI写文章
6 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
yfgcq
2007-04-14
打赏
举报
回复
呵呵
终于自己解决了
我在动态加载的时候,重新指定了个编码utf_8
adverse
2007-04-13
打赏
举报
回复
上面那个有点问题,修改了一下
function chinesefromutf8url(strutf8)
{
var bstr = "";
var noffset = 0;
// processing point on strutf8
if (strutf8 == "")
return "";
strutf8 = strutf8.toLowerCase();
noffset = strutf8.indexOf("%e");
if (noffset == -1)
return strutf8;
while (noffset != -1)
{
bstr += strutf8.substr(0, noffset);
strutf8 = strutf8.substr(noffset, strutf8.length - noffset);
if (strutf8 == "" || strutf8.length < 9) // bad string
return bstr;
bstr += utf8codetochinesechar(strutf8.substr(0, 9));
strutf8 = strutf8.substr(9, strutf8.length - 9);
noffset = strutf8.indexOf("%e");
}
return bstr + strutf8;
}
function unicodefromutf8(strutf8)
{
var bstr = "";
var ntotalchars = strutf8.length; // total chars to be processed.
var noffset = 0; // processing point on strutf8
var nremainingbytes = ntotalchars; // how many bytes left to be converted
var noutputposition = 0;
var icode, icode1, icode2; // the value of the unicode.
while (noffset < ntotalchars)
{
icode = strutf8.charcodeat(noffset);
if ((icode & 0x80) == 0) // 1 byte.
{
if ( nremainingbytes < 1 ) // not enough data
break;
bstr += string.fromcharcode(icode & 0x7f);
noffset++;
nremainingbytes -= 1;
}
else if ((icode & 0xe0) == 0xc0) // 2 bytes
{
icode1 = strutf8.charcodeat(noffset + 1);
if ( nremainingbytes < 2 || (icode1 & 0xc0) != 0x80 ) // invalid pattern
{
break;
}
bstr += string.fromcharcode(((icode & 0x3f) << 6) | ( icode1 & 0x3f));
noffset += 2;
nremainingbytes -= 2;
}
else if ((icode & 0xf0) == 0xe0) // 3 bytes
{
icode1 = strutf8.charcodeat(noffset + 1);
icode2 = strutf8.charcodeat(noffset + 2);
if ( nremainingbytes < 3 || // not enough data
(icode1 & 0xc0) != 0x80 || // invalid pattern
(icode2 & 0xc0) != 0x80 )
{
break;
}
bstr += string.fromcharcode(((icode & 0x0f) << 12) | ((icode1 & 0x3f) << 6) | (icode2 & 0x3f));
noffset += 3;
nremainingbytes -= 3;
}
else // 4 or more bytes -- unsupported
break;
}
if (nremainingbytes != 0)
{
// bad utf8 string.
return "";
}
return bstr;
}
function utf8codetochinesechar(strutf8)
{
var icode, icode1, icode2;
icode = parseInt("0x" + strutf8.substr(1, 2));
icode1 = parseInt("0x" + strutf8.substr(4, 2));
icode2 = parseInt("0x" + strutf8.substr(7, 2));
return String.fromCharCode(((icode & 0x0f) << 12) | ((icode1 & 0x3f) << 6) | (icode2 & 0x3f));
}
alert(chinesefromutf8url("%e6%b5%8b%e8%af%95"))
adverse
2007-04-13
打赏
举报
回复
看看这个js方法好使吗
function chinesefromutf8url(strutf8)
{
var bstr = "";
var noffset = 0;
// processing point on strutf8
if (strutf8 == "")
return "";
strutf8 = strutf8.tolowercase();
noffset = strutf8.indexof("%e");
if (noffset == -1)
return strutf8;
while (noffset != -1)
{
bstr += strutf8.substr(0, noffset);
strutf8 = strutf8.substr(noffset, strutf8.length - noffset);
if (strutf8 == "" || strutf8.length < 9) // bad string
return bstr;
bstr += utf8codetochinesechar(strutf8.substr(0, 9));
strutf8 = strutf8.substr(9, strutf8.length - 9);
noffset = strutf8.indexof("%e");
}
return bstr + strutf8;
}
function unicodefromutf8(strutf8)
{
var bstr = "";
var ntotalchars = strutf8.length; // total chars to be processed.
var noffset = 0; // processing point on strutf8
var nremainingbytes = ntotalchars; // how many bytes left to be converted
var noutputposition = 0;
var icode, icode1, icode2; // the value of the unicode.
while (noffset < ntotalchars)
{
icode = strutf8.charcodeat(noffset);
if ((icode & 0x80) == 0) // 1 byte.
{
if ( nremainingbytes < 1 ) // not enough data
break;
bstr += string.fromcharcode(icode & 0x7f);
noffset++;
nremainingbytes -= 1;
}
else if ((icode & 0xe0) == 0xc0) // 2 bytes
{
icode1 = strutf8.charcodeat(noffset + 1);
if ( nremainingbytes < 2 || (icode1 & 0xc0) != 0x80 ) // invalid pattern
{
break;
}
bstr += string.fromcharcode(((icode & 0x3f) << 6) | ( icode1 & 0x3f));
noffset += 2;
nremainingbytes -= 2;
}
else if ((icode & 0xf0) == 0xe0) // 3 bytes
{
icode1 = strutf8.charcodeat(noffset + 1);
icode2 = strutf8.charcodeat(noffset + 2);
if ( nremainingbytes < 3 || // not enough data
(icode1 & 0xc0) != 0x80 || // invalid pattern
(icode2 & 0xc0) != 0x80 )
{
break;
}
bstr += string.fromcharcode(((icode & 0x0f) << 12) | ((icode1 & 0x3f) << 6) | (icode2 & 0x3f));
noffset += 3;
nremainingbytes -= 3;
}
else // 4 or more bytes -- unsupported
break;
}
if (nremainingbytes != 0)
{
// bad utf8 string.
return "";
}
return bstr;
}
function utf8codetochinesechar(strutf8)
{
var icode, icode1, icode2;
icode = parseint("0x" + strutf8.substr(1, 2));
icode1 = parseint("0x" + strutf8.substr(4, 2));
icode2 = parseint("0x" + strutf8.substr(7, 2));
return string.fromcharcode(((icode & 0x0f) << 12) | ((icode1 & 0x3f) << 6) | (icode2 & 0x3f));
}
alert(chinesefromutf8url("%e6%b5%8b%e8%af%95"))
lizhongbin
2007-04-13
打赏
举报
回复
帮楼主顶。。。
adverse
2007-04-13
打赏
举报
回复
觉得最好还是把.txt文件的编码改了.
用记事本打开,另存为,编码选择ANSI就可以了.
adverse
2007-04-13
打赏
举报
回复
function utf2gb(utfstr)
for dig=1 to len(utfstr)
if mid(utfstr,dig,1)="%" then
if len(utfstr) >= dig+8 then
gbstr=gbstr & convchinese(mid(utfstr,dig,9))
dig=dig+8
else
gbstr=gbstr & mid(utfstr,dig,1)
end if
else
gbstr=gbstr & mid(utfstr,dig,1)
end if
next
utf2gb=gbstr
end function
function convchinese(x)
a=split(mid(x,2),"%")
i=0
j=0
for i=0 to ubound(a)
a(i)=c16to2(a(i))
next
for i=0 to ubound(a)-1
digs=instr(a(i),"0")
unicode=""
for j=1 to digs-1
if j=1 then
a(i)=right(a(i),len(a(i))-digs)
unicode=unicode & a(i)
else
i=i+1
a(i)=right(a(i),len(a(i))-2)
unicode=unicode & a(i)
end if
next
if len(c2to16(unicode))=4 then
convchinese=convchinese & chrw(int("&h" & c2to16(unicode)))
else
convchinese=convchinese & chr(int("&h" & c2to16(unicode)))
end if
next
end function
function c2to16(x)
i=1
for i=1 to len(x) step 4
c2to16=c2to16 & hex(c2to10(mid(x,i,4)))
next
end function
function c2to10(x)
c2to10=0
if x="0" then exit function
i=0
for i= 0 to len(x) -1
if mid(x,len(x)-i,1)="1" then c2to10=c2to10+2^(i)
next
end function
function c16to2(x)
i=0
for i=1 to len(trim(x))
tempstr= c10to2(cint(int("&h" & mid(x,i,1))))
do while len(tempstr)<4
tempstr="0" & tempstr
loop
c16to2=c16to2 & tempstr
next
end function
function c10to2(x)
mysign=sgn(x)
x=abs(x)
digs=1
do
if x<2^digs then
exit do
else
digs=digs+1
end if
loop
tempnum=x
i=0
for i=digs to 1 step-1
if tempnum>=2^(i-1) then
tempnum=tempnum-2^(i-1)
c10to2=c10to2 & "1"
else
c10to2=c10to2 & "0"
end if
next
if mysign=-1 then c10to2="-" & c10to2
end function
WEB开发文档2 总结
转自:http://blog.donews.com/lvjiyong/archive/2006/06/29/931071.aspx怎样将后台生成的在内存中的图象显示到客户端Microsoft IE WebControls下载地址如何在DATAGRID中使用JAVASCRIPT脚本控制DataGrid中连接到下一页显示数据下载中文名文件时保存文件名
乱码
问题关于用ASP.net绘图的问题,请大虾指教那
HTML ASP VBSCRIPT JAVASCRIPT SKILLS 常见问题
1.如何 最小化、最大化、关闭窗口答:2.如何静止页面缓存答:htm网页或者asp网页response.expires=-1response.expiresabsolute=now()-1response.cachecontrol="no-cache"php网页header("expires:mon,26j
webmagic采集CSDN的Java_WebDevelop页面
使用webmagic采集博客类的网站示例
vb/vb.net开发技巧荟萃(七)
Domino下使用Wininet的FtpGetFile方法下载文件失败 求指教,视屏监控接口如何写?? filelistbox如何排序? 关于数据库的两个小问题 “VB与EXCEL、VB与ACCESS”的问题 VB画线 百思不得其解VB编小程序的错误 求牛人指导 我新手 VB 如何打开 指定的 TCP端口? VB6.0获取计算机名 用户名最简单的方法 如...
Java:56-项目实战
响应结果: 前后端分离架构的优势 前后端耦合的开发方式 这种方式中 Java程序员又当爹又当妈,又搞前端,又搞后端 正所谓术业有专攻,一个人如果什么都会,那么他肯定也什么都精 创建Maven项目: IDEA中配置并创建Maven 打开IDEA 创建一个新的project 点击Maven的项目创建,名称随便自己写 Maven工程改造: 当前创建的maven项目是一个 普通的Java项目,不是web项目,我们要进行一下改造 在main目录下创建一个webapp文件夹 out存放资源,临时服务器存放操作后
JavaScript
87,996
社区成员
224,708
社区内容
发帖
与我相关
我的任务
JavaScript
Web 开发 JavaScript
复制链接
扫一扫
分享
社区描述
Web 开发 JavaScript
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章