找回密碼
 註冊
搜索
查看: 5803|回復: 0

判斷當前字元是英文字元還是中文字元(JavaScript)

[複製鏈接]
發表於 2005-12-19 15:19:26 | 顯示全部樓層 |閱讀模式
/*判斷當前字符是英文字符還是中文字符*/
function ifWesternChr(chrInput)
{  
var chrInput_e;
chrInput_e=escape(chrInput);
if(chrInput_e.length==(chrInput.length)*6 || chrInput=="\r" || chrInput=="\n")
return false; /*只有非普通ASCII字符經過escape()函數編碼之後的長度才會等於原長度的6倍,所以用這種方法可以避開內碼直接判斷當前字符是否為中文。*/
else
return true;
/* true 是英文, false 是中文 */
}
您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則

Archiver|手機版|彩色筆小沛的知識庫

GMT+8, 2024-5-7 02:21 , Processed in 0.015436 second(s), 9 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回復 返回頂部 返回列表