・半角カタカナ “ア”~“ン”、“ァ”~“ォ”、“ャ”~“ョ”、“ッ”、“゙”、“゚”、“ー”(’ff66’~’ff9f’)
・全角カタカナ “ア”~“ン”、“ガ”~“ボ”、“パ”~“ポ”、“ァ”~“ォ”、“ャ”~“ョ”、“ッ”、“ヮ”、“ヵ”、“ヶ”、“ヰ”、“ヱ”(’30a1’~’30f6’)
・全角ひらがな “あ”~“ん”、“が”~“ぼ”、“ぱ”~“ぽ”、“ぁ”~“ぉ”、“ゃ”~“ょ”、“っ”、“ゎ”、“ゐ”、“ゑ”(’3041’~’3093’)
・半角英字 “A”~“Z”、“a”~“z”(’0041’~’005a’、’0061’~’007a’)
・全角英字 “A”~“Z”、“a”~“z”(’ff21’~’ff3a’、’ff41’~’ff5a’)
・半角もしくは全角ハイフン及び長音記号 “-”、“-”、“ー”、“‐”(’002d’、’ff0d’、’2212’、’30fc’、’2010’)
可否用这个逻辑: 00-FF之间+”(’ff66’~’ff9f’)是半角,其他为全角?
小程序输入日文半角40个,全角20个。
function textareaLimit()
{
var strCode;
var strLength;
var s=$("tekiyo").value;
for(var i=0;i<s.length;i++)
{
strCode = s.charCodeAt(i);
if(!((strCode > 0x00 && strCode < 0xFF)|| (strCode > 0xff66 && strCode < 0xff99ff)))
{
strLength=20;
break;
}
else
{
strLength=40;
}
}
if($("tekiyo").value.length>strLength)
{
return false;
}
else
{
return true;
}
}
小练习:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>日文全角和半角的区别!</title>
</head>
<body>
<script>
function textareaLimit()
{
var strCode;
var strLength;
var s=document.getElementById("tekiyo").value;
for(var i=0;i<s.length;i++)
{
strCode = s.charCodeAt(i);
if(!((strCode > 0x00 && strCode < 0xFF)|| (strCode > 0xff66 && strCode < 0xff99ff)))
{
strLength=20;
break;
}
else
{
strLength=40;
}
}
if(s.length>strLength)
{
return false;
}
else
{
return true;
}
}
function check()
{
if(!textareaLimit())
{
alert("超出限定长度!");
return;
}
}
</script>
<textarea id="tekiyo" style="width:350px;height:50px;" οnkeypress="check()" οnkeydοwn="check()" οnpaste="return false"></textarea>
</body>
</html>
http://hi.baidu.com/maplenet/blog/item/d5ffa74359dca0169313c69a.html
JavaScript区别日文全角与半角(转)
最新推荐文章于 2025-04-01 10:43:54 发布