javascript实现unicode和字符的互相转换
2024-09-06 12:41:59
供稿:网友
<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;
}
}
}
}
</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);
}
return(st.toUpperCase());
}
else {
return('');
}
}
var http_request = false;
function getRequest(url) {
http_request = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
http_request = new XMLHttpRequest();