写个js半角全角互相转换吧.其实网上有的是.这个是借助网上看的,然后自己研究出来的.简单测试了下.还好用.呵呵.
有问题的话请帮助指出.我会马上修改的.希望大家常来.我是新手.请多多指教.
<!--
//+------------------------------
//|create by : ieclipse
//|date : 2008-02-22
//|content : js半角全角互相转换
//+------------------------------
-->
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
< HTML >
< HEAD >
< TITLE > js半角全角互相转换 </ TITLE >
</ HEAD >
< script language ="javascript" > ...
function stringToChange(str, boo)
...{
var result = "";
var charlist ="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
charlist += "abcdefghijklmnopqrstuvwxyz";
charlist += "0123456789";
charlist += " `~!@#$%^&*()_+-={}|[]:/";'<>?,./";//半角空格
for(var i = 0; i < str.length; i++)//字符串str中的字符
...{
var c1 = str.charAt(i);
var c2 = str.charCodeAt(i);
if(charlist.indexOf(c1) > -1)
...{
if(" " == c1)
...{
result += " ";
}else
...{
result += String.fromCharCode(str.charCodeAt(i) + 65248);
}
}else
...{
if(boo > 0)
...{
result += String.fromCharCode(str.charCodeAt(i));
}else
...{
if(" " == c1)
...{
result += " ";
}else
...{
if(charlist.indexOf(String.fromCharCode(str.charCodeAt(i) - 65248)) > -1)
...{
result += String.fromCharCode(str.charCodeAt(i) - 65248);
}else
...{
result += String.fromCharCode(str.charCodeAt(i));
}
}
}
}
}
return result;
}
</ script >
< BODY >
< input type ="text" name ="t1" size ="100" value ="123 abc ABC `~!@#$%^&*()_+-={}[]|,.<>/?;:'少双引号" >< p >
< input type ="text" name ="t2" size ="100" value ="123 abc ABC `~!@#$%^&*()_+-={}[]|\,.<>/?;:'少双引号" >< p >
< input type ="button" name ="b1" value ="转为双字节字符" onclick ="t3.value = stringToChange(t1.value, 1);" >< t >< input type ="button" name ="b2" value ="转为单字节字符" onclick ="t3.value = stringToChange(t2.value, 0);" >< p >
< input type ="text" name ="t3" size ="100" value ="" >< p >
</ BODY >
</ HTML >
//+------------------------------
//|create by : ieclipse
//|date : 2008-02-22
//|content : js半角全角互相转换
//+------------------------------
-->
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
< HTML >
< HEAD >
< TITLE > js半角全角互相转换 </ TITLE >
</ HEAD >
< script language ="javascript" > ...
function stringToChange(str, boo)
...{
var result = "";
var charlist ="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
charlist += "abcdefghijklmnopqrstuvwxyz";
charlist += "0123456789";
charlist += " `~!@#$%^&*()_+-={}|[]:/";'<>?,./";//半角空格
for(var i = 0; i < str.length; i++)//字符串str中的字符
...{
var c1 = str.charAt(i);
var c2 = str.charCodeAt(i);
if(charlist.indexOf(c1) > -1)
...{
if(" " == c1)
...{
result += " ";
}else
...{
result += String.fromCharCode(str.charCodeAt(i) + 65248);
}
}else
...{
if(boo > 0)
...{
result += String.fromCharCode(str.charCodeAt(i));
}else
...{
if(" " == c1)
...{
result += " ";
}else
...{
if(charlist.indexOf(String.fromCharCode(str.charCodeAt(i) - 65248)) > -1)
...{
result += String.fromCharCode(str.charCodeAt(i) - 65248);
}else
...{
result += String.fromCharCode(str.charCodeAt(i));
}
}
}
}
}
return result;
}
</ script >
< BODY >
< input type ="text" name ="t1" size ="100" value ="123 abc ABC `~!@#$%^&*()_+-={}[]|,.<>/?;:'少双引号" >< p >
< input type ="text" name ="t2" size ="100" value ="123 abc ABC `~!@#$%^&*()_+-={}[]|\,.<>/?;:'少双引号" >< p >
< input type ="button" name ="b1" value ="转为双字节字符" onclick ="t3.value = stringToChange(t1.value, 1);" >< t >< input type ="button" name ="b2" value ="转为单字节字符" onclick ="t3.value = stringToChange(t2.value, 0);" >< p >
< input type ="text" name ="t3" size ="100" value ="" >< p >
</ BODY >
</ HTML >
其实这段代码有很多问题存在.我就不多说了.大家可以自己根据需要更改.
如有更好的方法请回信.共同研究.呵呵.