encode|js| Pinyin
Often written in VB Urlencoding is easy to achieve urlencode, as well as the use
http://www.csdn.net/Develop/read_article.asp?id=13846
The code in can easily be rewritten as a VBS to achieve the pinyin of some Chinese characters
But because some people need to write completely in JavaScript, JavaScript defaults to Unicode
So you need a Unicode and GB conversion library.
Unicode and GB conversion libraries and UrlEncode and Getspell functions, please download
Http://www.blueidea.com/user/qswh/qswhU2GB.js
var qswhu2gb=[];//unicode and GB of corresponding tables, slightly
var qswhspell=[];//pinyin comparison table, slightly
function urlencode (str) {
var i,c,ret= ", strspecial="!\ "#$%&" () *+,/:;<= >?@[\]^ ' {|} ~%";
for (i=0;i<str.length;i++) {
if (str.charcodeat (i) >=0x4e00) {
c=qswhu2gb[ Str.charcodeat (i) -0x4e00];
ret+= "%" +c.slice (0,2) + "%" +c.slice (-2);
}
else{
C=str.charat (i);
if (c== "")
ret+= "+";
Else if (Strspecial.indexof (c)!=-1)
ret+= "%" +str.charcodeat (i). ToString (a);
else
ret+=c;
}
return ret;
}
function Getspell (STR,SP) {
var i,c,t,ret= "";
if (sp==null) sp= "";
for (i=0;i<str.length;i++) {
if (Str.charcodeat (i) >=0x4e00) {
C=parseint (Qswhu2gb[str.charcodeat (i) -0x4e00],16);
if (c<55290) {
for (t=qswhspell.length-1;t>0;t=t-2) if (qswhspell[t]<=c) break;
if (t>0) ret+=qswhspell[t-1]+sp;
}
}
}
Return Ret.substr (0,ret.length-sp.length);
}
The SP is a separator, as the following example
<script Language=javascript src=qswhu2gb.js></script>
<script language=javascript>
document.write (UrlEncode ("Chinese <>\" #%{}|^~[] ' &?+abc ")," <br> ")
document.write (Getspell ("Chinese Programmer's Base"), "<br>"
document.write ("Getspell", "'"), "<br>")
</script>