📄 23.19 全角转半角.htm
字号:
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>标题页</title>
<script LANGUAGE="JavaScript">
function fullChar2halfChar(str)
{
var result = '';
for (i=0 ; i<str.length; i++)
{
code = str.charCodeAt(i); //获取当前字符的unicode编码
if (code >= 65281 && code <= 65373) //unicode编码范围是所有的英文字母以及各种字符
{
result += String.fromCharCode(str.charCodeAt(i) - 65248); //把全角字符的unicode编码转换为对应半角字符的unicode码
}
else if (code == 12288) //空格
{
result += String.fromCharCode(str.charCodeAt(i) - 12288 + 32);//半角空格
}else
{
result += str.charAt(i); //原字符返回
}
}
return result;
}
</script>
</head>
<body>
全角<input type=text name="txt1" value="this is !"><br />
半角<input type=text name="txt2" value="">
<input type=button value="转换文本" onClick="txt2.value=fullChar2halfChar(txt1.value)">
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -