zoukankan      html  css  js  c++  java
  • 文本框仅允许输入大于0的正整数

    系统有个栏位,作为参数设置,限制用户只能输入大于0的正整数:

    <input type="text" name="non" ng-model="non" 
                        onpaste="return false;"
                        onkeyup="if (
                                        this.value.length == 1
                                    ) {
                                        this.value = this.value.replace(/[^1-9]/g, '')
                                    }
                                    else {
                                        this.value = this.value.replace(/D/g, '')
                                    }"
                        onafterpaste="if (
                                        this.value.length == 1) {
                                        this.value = this.value.replace(/[^1-9]/g, '0')
                                    }
                                    else {
                                        this.value = this.value.replace(/D/g, '')
                                    }" />
    Source Code

    上面有一个onpaste属性,即是说,此文本框不接受粘贴数据。

  • 相关阅读:
    bzoj1797
    bzoj1266
    bzoj1497
    bzoj1412
    bzoj3156
    JSOI2014第三轮总结
    bzoj1855
    bzoj1044
    codeforces 371D
    codeforces 371B
  • 原文地址:https://www.cnblogs.com/insus/p/12504321.html
Copyright © 2011-2022 走看看