一、用JS把 全角转换成半角(不能转换标点符号) input type="text" size="10" maxlength="10" οnkeyup="javascript:var t = ''; with(this.value) { for (var i = 0; i length; i++) t += (65296 = charCodeAt(i) charCodeAt(i) = 653
一、用JS把
全角转换成半角(不能转换标点符号)
<input type="text" size="10" maxlength="10"
οnkeyup="javascript:var t = ''; with(this.value) { for (var i = 0; i < length; i++) t += (65296 <=
charCodeAt(i) &&
charCodeAt(i) <= 65305) ? String.fromCharCode(
charCodeAt(i) - 65248) : charAt(i); } this.value = t;" />
<br>
<br>
二、用JS把
全角转换成半角的函数
<textarea name="n" type="text" id="n" οnkeyup="CtoH(this);" style="width:100%;height:100%;"></textarea>
<SCRIPT>
function CtoH(obj){
var str=obj.value;
var result="";
for (var i = 0; i < str.length; i++){
if (str.
charCodeAt(i)==12288){
result+= String.fromCharCode(str.
charCodeAt(i)-12256);
continue;
}
if (str.
charCodeAt(i)>65280 && str.
charCodeAt(i)<65375) result+= String.fromCharCode(str.
charCodeAt(i)-65248);
else result+= String.fromCharCode(str.
charCodeAt(i));
}
obj.value=result;
}
</SCRIPT>
<BR>
<BR>
三、用JS把
全角转换成半角(只允许输入数字、小数点与负号)
<input
οnkeypress="var k=event.keyCode; return k>=48&&k<=57||k==46||k==45"
οnpaste="return !clipboardData.getData('text').match(/\D/)"
οndragenter="return false" style="ime-mode:Disabled"
>
<br>
<br>
四、用JS把
全角转换成半角(只允许输入数字)
<input
οnkeypress="var k=event.keyCode; return k>=48&&k<=57"
οnpaste="return !clipboardData.getData('text').match(/\D/)"
οndragenter="return false" style="ime-mode:Disabled"
>
<br><br>
五、不允许输入
全角字符
<INPUT name="CardId" onKeyUp="quanjiao(this);">
<script language="javascript">
function quanjiao(obj){
var str=obj.value;
if (str.length>0){
for (var i = str.length-1; i >= 0; i--){
unicode=str.
charCodeAt(i);
if (unicode>65280 && unicode<65375){
alert("不能输入
全角字符,请输入半角字符");
obj.value=str.substr(0,i);
}
}
}
}
<script type="text/javascript"><!-- google_ad_client = "pub-6770445892601887"; /* 468x60, 创建于 09-11-19 */ google_ad_slot = "4437639877"; google_ad_width = 468; google_ad_height = 60; //--> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>