分享

限制文本框只能输入数字

 aolingping 2011-11-30
<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,'')",该方法是限制输入为中文

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多