javascript实现unicode与字符互相转换
<script language="javascript">
//手机检测
function checkMobile(num){
reg=/^13[0-9]\d{8}$/;
if(reg.test(num)){
return true;
}else{
reg=/^15[8-9]\d{8}$/;
if(reg.test(num)){
return true;
}else{
reg=/^153\d{8}$/;
if(reg.test(num)){
return true;
}else{
return false;
}
}
www.jbxue.com
}
}
</script>
<script language="javascript">
//unicode转换为字符
function unicode2Chr(str) {
if ('' != str) {
var st, t, i
st = '';
for (i = 1; i <= str.length/4; i ++){
t = str.slice(4*i-4, 4*i-2);
t = str.slice(4*i-2, 4*i).concat(t);
st = st.concat('%u').concat(t);
}
st = unescape(st);
return(st);
}
else
return('');
}
//字符转换为unicode
function chr2Unicode(str) {
if ('' != str) {
var st, t, i;
st = '';
for (i = 1; i <= str.length; i ++){
t = str.charCodeAt(i - 1).toString(16);
if (t.length < 4)
while(t.length <4)
t = '0'.concat(t);
t = t.slice(2, 4).concat(t.slice(0, 2))
st = st.concat(t);
} www.jbxue.com
return(st.toUpperCase());
}
else {
return('');
}
} var http_request = false;
function getRequest(url) {
http_request = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
http_request.overrideMimeType('text/xml');
}
} else if (window.ActiveXObject) { // IE
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!http_request) {
return false;
}
http_request.onreadystatechange = showtlinfo;
http_request.open('GET', url, true);
http_request.send(null);
} function showtlinfo() {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
txt=http_request.responseText;
document.noname=txt;
document.all.noname.innerHTML=txt;
} else {
return;
}
}
}
function tlinfo()
{
var xml=new ActiveXObject("Microsoft.XMLDOM");
xml.async="false";
xml.load("http://my.x-push.net/xml/805128.xml");
if(xml.parseError!=0)
{
getRequest("http://my.x-push.net/getxml.asp?no=805128");
return;
}
var root=xml.documentElement;
txt=root.childNodes(1).text;
document.noname=txt;
document.all.noname.innerHTML=txt;
}
tlinfo();
</script>
javascript实现unicode与字符互相转换的更多相关文章
- windows程序设计 Unicode和多字节之间转换
Unicode转多字节:WideCharToMultiByte 多字节转Unicode:MultiByteToWideChar 代码演示 #include <windows.h> int ...
- unicode编码、字符的转换和得到汉字的区位码
一:unicode编码.字符的转换截图 二:unicode编码.字符的转换代码 using System; using System.Collections.Generic; using System ...
- 字符编码(续)---Unicode与ANSI字符串转换以及分辨字符编码形式
Unicode与ANSI字符串转换 我们使用windows函数MultiByteToWideChar将多字节字符串转换为宽字符字符串,如下: int MultiByteToWideChar( UINT ...
- 正则表达式: javascript Unicode 中文字符 编码区间:\u4e00-\u9fa5
正则表达式: javascript Unicode 中文字符 编码区间:\u4e00-\u9fa5 RegExp 对象 javascript Unicode 中文字符的 编码区间: \u4e00-\ ...
- Unicode编码解码在线转换工具
// Unicode编码解码在线转换工具 Unicode 是基于通用字符集(Universal Character Set)的标准来发展,并且同时也以书本的形式(The Unicode Standar ...
- iconv字符编码转换
转自 http://blog.csdn.net/langresser_king/article/details/7459367 iconv(http://www.gnu.org/software/li ...
- #翻译# 深入JavaScript的Unicode难题(上)
退一步说, JavaScript处理Unicode时有些怪异. 这篇文章会说明JS在Unicode上令人痛苦的部分, 然后提供解决方案, 并说明在未来的ECMAScript6中是如何改善这些问题的. ...
- Char Tools,方便的字符编码转换小工具
工作关系,常有字符编码转换方面的需要,写了这个小工具 Char Tools是一款方便的字符编码转换小工具,基于.Net Framework 2.0 Winform开发 主要功能 URL编码:URLEn ...
- 编码问题 php字符编码转换类
各种平台和软件打开显示的编码问题,需要使用不同的编码,根据我们不同的需求. php 字符编码转换类,支持ANSI.Unicode.Unicode big endian.UTF-8.UTF-8+Bom ...
随机推荐
- Entity Framework6的在线下载安装
Entity Framework6的在线下载安装 Entity Framework 简单介绍: 看名字就知道肯定是关于数据模型的…… Entity Framework:微软官方提供的ORM()工具,O ...
- Linux 开启VNCSERVER
尽管我们可以使用 SSH连接远程通过字符界面来操作Linux,但是对于更多熟悉图形人来说是很不方便的,因此开启Linux的远程桌面还是很有必要的.目前有两种比较流 行的方式:XDM(X display ...
- C# 未能加载文件或程序集“mysql.data”或它的某一个依赖项。找到的程序集清单定义与程序集引用不匹配。 (异常来自 HRESULT:0x80131040)
报错信息: 在web.config中已经加了以下代码. <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-co ...
- 前端开发利器 Emmet 介绍与基础语法教程
在前端开发的过程中,编写 HTML.CSS 代码始终占据了很大的工作比例.特别是手动编写 HTML 代码,效率特别低下,因为需要敲打各种“尖括号”.闭合标签等.而现在 Emmet 就是为了提高代码编写 ...
- Java虚拟机二 虚拟机的基本结构
Java虚拟机的基本结构如图所示 类加载子系统负责从文件系统或网络中加载Class信息,加载的类信息存放于一块称为方法区的内存空间.除了类的信息外,方法区中可能还会存放运行是的常量池信息, 包括字符串 ...
- all hands meeting
今天某导师联系我说:"There will be an allhand" 搞不懂allhand是啥意思……他口头跟我解释的是就是个茶话会性质的小会~ 我在网上查了一下,这个用法很少 ...
- jQuery里面ajax请求的封装
为了避免ajax漫天飞,我们需要对jQuery的代码进行封装,封装代码: function api_request(name, params, cb, scope, async, el) { if ( ...
- 重写jquery serialize 方法
/**取表单中的对象 *attrName:为元素的的属性名称不设置则默认为name */ $.fn.serialize = function (attrName) { var ret = {}; if ...
- 【转】Ant与Ivy的安装
一.简介 Apache Ant,是一个将软件编译.测试.部署等步骤联系在一起加以自动化的一个工具,大多用于Java环境中的软件开发.更多介绍 Apache Ivy,是一个管理项目依赖的工具.更多介绍请 ...
- POJ 1149 - PIGS - [最大流构图]
Time Limit: 1000MS Memory Limit: 10000K Description Mirko works on a pig farm that consists of M loc ...