JS 字符替换实现代码
作者:
可能你不想用户直接复制数字,或不想让自动抓取程序获取的QQ号。那可以将数字替换成汉字或其他用户可是识别的文字!
15684682345
一五六八四六八二三四五
15684682345
壹伍陆捌肆陆捌贰叁肆伍
㈠㈤㈥㈧㈣㈥㈧㈡㈢㈣㈤
ⅠⅤⅥⅧⅣⅥⅧⅡⅢⅣⅤ
①⑤⑥⑧④⑥⑧②③④⑤
⒈⒌⒍⒏⒋⒍⒏⒉⒊⒋⒌
⑴⑸⑹⑻⑷⑹⑻⑵⑶⑷⑸
asdfwegsgg
ASDFWEGSGG
⒜⒮⒟⒡⒲⒠⒢⒮⒢⒢
ⓐⓢⓓⓕⓦⓔⓖⓢⓖⓖ
㋊㏬㍭
var num1 = '0123456789';
var num2 = '零一二三四五六七八九';
var num3 = '0123456789';
var num4 = '零壹贰叁肆伍陆柒捌玖';
var num5 = '〇㈠㈡㈢㈣㈤㈥㈦㈧㈨';
var num6 = '〇ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩ';
var num7 = '〇①②③④⑤⑥⑦⑧⑨';
var num8 = '〇⒈⒉⒊⒋⒌⒍⒎⒏⒐';
var num9 = '〇⑴⑵⑶⑷⑸⑹⑺⑻⑼';
var z1 = 'abcdefghijklmnopqrstuvwxyz';
var z2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
var z3 = '⒜⒝⒞⒟⒠⒡⒢⒣⒤⒥⒦⒧⒨⒩⒪⒫⒬⒭⒮⒯⒰⒱⒲⒳⒴⒵';
var z4 = 'ⓐⓑⓒⓓⓔⓕⓖⓗⓘⓙⓚⓛⓜⓝⓞⓟⓠⓡⓢⓣⓤⓥⓦⓧⓨⓩ';
var month = '㋀㋁㋃㋂㋄㋅㋆㋇㋈㋉㋊㋋';
var day = '㏠㏡㏢㏣㏤㏥㏦㏧㏨㏩㏪㏫㏬㏭㏮㏯㏰㏱㏲㏳㏴㏵㏶㏷㏸㏹㏺㏻㏼㏽㏾';
var hour = '㍘㍙㍚㍛㍜㍝㍞㍟㍠㍡㍢㍣㍤㍥㍦㍧㍨㍩㍪㍫㍬㍭㍮㍯㍰';
function showNum(o, num)
{
var strHTML = '';
num += '';
for (n=0; n< num.length; n++){
strHTML += o.charAt(parseInt(num.charAt(n),10));
}
document.write(strHTML);
document.write('<br>');
}
function showZ(o, str)
{
var strHTML = '';
for (n=0; n< str.length; n++){
var chr = str.charAt(n);
var index = z1.indexOf(chr);
if(index == -1)index = z2.indexOf(chr);
strHTML += (index == -1 ? chr : o.charAt(index));
}
document.write(strHTML);
document.write('<br>');
}
function showDay(m, d, h)
{
var strHTML = '';
strHTML += month.charAt(m-1);
strHTML += day.charAt(d-1);
if(h != null){
strHTML += hour.charAt(h);
}
document.write(strHTML);
document.write('<br>');
}
转载自[ http://www.cnblogs.com/zjfree/ ]
一五六八四六八二三四五
15684682345
壹伍陆捌肆陆捌贰叁肆伍
㈠㈤㈥㈧㈣㈥㈧㈡㈢㈣㈤
ⅠⅤⅥⅧⅣⅥⅧⅡⅢⅣⅤ
①⑤⑥⑧④⑥⑧②③④⑤
⒈⒌⒍⒏⒋⒍⒏⒉⒊⒋⒌
⑴⑸⑹⑻⑷⑹⑻⑵⑶⑷⑸
asdfwegsgg
ASDFWEGSGG
⒜⒮⒟⒡⒲⒠⒢⒮⒢⒢
ⓐⓢⓓⓕⓦⓔⓖⓢⓖⓖ
㋊㏬㍭
15684682345
一五六八四六八二三四五
15684682345
壹伍陆捌肆陆捌贰叁肆伍
㈠㈤㈥㈧㈣㈥㈧㈡㈢㈣㈤
ⅠⅤⅥⅧⅣⅥⅧⅡⅢⅣⅤ
①⑤⑥⑧④⑥⑧②③④⑤
⒈⒌⒍⒏⒋⒍⒏⒉⒊⒋⒌
⑴⑸⑹⑻⑷⑹⑻⑵⑶⑷⑸
asdfwegsgg
ASDFWEGSGG
复制代码 代码如下:
var num1 = '0123456789';
var num2 = '零一二三四五六七八九';
var num3 = '0123456789';
var num4 = '零壹贰叁肆伍陆柒捌玖';
var num5 = '〇㈠㈡㈢㈣㈤㈥㈦㈧㈨';
var num6 = '〇ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩ';
var num7 = '〇①②③④⑤⑥⑦⑧⑨';
var num8 = '〇⒈⒉⒊⒋⒌⒍⒎⒏⒐';
var num9 = '〇⑴⑵⑶⑷⑸⑹⑺⑻⑼';
var z1 = 'abcdefghijklmnopqrstuvwxyz';
var z2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
var z3 = '⒜⒝⒞⒟⒠⒡⒢⒣⒤⒥⒦⒧⒨⒩⒪⒫⒬⒭⒮⒯⒰⒱⒲⒳⒴⒵';
var z4 = 'ⓐⓑⓒⓓⓔⓕⓖⓗⓘⓙⓚⓛⓜⓝⓞⓟⓠⓡⓢⓣⓤⓥⓦⓧⓨⓩ';
var month = '㋀㋁㋃㋂㋄㋅㋆㋇㋈㋉㋊㋋';
var day = '㏠㏡㏢㏣㏤㏥㏦㏧㏨㏩㏪㏫㏬㏭㏮㏯㏰㏱㏲㏳㏴㏵㏶㏷㏸㏹㏺㏻㏼㏽㏾';
var hour = '㍘㍙㍚㍛㍜㍝㍞㍟㍠㍡㍢㍣㍤㍥㍦㍧㍨㍩㍪㍫㍬㍭㍮㍯㍰';
function showNum(o, num)
{
var strHTML = '';
num += '';
for (n=0; n< num.length; n++){
strHTML += o.charAt(parseInt(num.charAt(n),10));
}
document.write(strHTML);
document.write('<br>');
}
function showZ(o, str)
{
var strHTML = '';
for (n=0; n< str.length; n++){
var chr = str.charAt(n);
var index = z1.indexOf(chr);
if(index == -1)index = z2.indexOf(chr);
strHTML += (index == -1 ? chr : o.charAt(index));
}
document.write(strHTML);
document.write('<br>');
}
function showDay(m, d, h)
{
var strHTML = '';
strHTML += month.charAt(m-1);
strHTML += day.charAt(d-1);
if(h != null){
strHTML += hour.charAt(h);
}
document.write(strHTML);
document.write('<br>');
}
转载自[ http://www.cnblogs.com/zjfree/ ]