<script> function nots() { if ((event.keyCode < 48) || (event.keyCode > 57)) event.returnValue = false; }//限制输入的字符为英文 </script> <input onkeypress="nots()" onkeyup="value=value.replace(/[^\daxychun]/g,'')" type="text" style="ime-mode:disabled; text-align:center; height:30px; border:none; color:#444444;" readonly="readonly"/>说明: onkeypress="nots()" 只能限制输入的字符不能为英文,但是不能限制输入的字符为中文。除了谷歌等浏览器目前不支持style="ime-mode“ 能限制中文输入法,即禁止切换中文输入法。所以在谷歌浏览器中要想限制输入的字符只能为数字,要使用onkeyup="value=value.replace(/[^\daxychun]/g,'')",该方法是限制输入为中文 |
|
来自: aolingping > 《技术》