输入框输入数值

1.输入正整数keyup事件 调用方法前阻止事件冒泡

function setPositiveNumber (input) {
        if(input.value.length == 1) {
            input.value = input.value.replace(/[^1-9]/g, '');
        } else {
            input.value = input.value.replace(/\D/g, '');
        }
        if (input.value > 0) {
            input.value = Number(input.value);
        }
    }

2.非负整数 监听键盘的keyup事件

function setWeight (e) {
            e.stopPropagation();
            this.value = this.value.replace(/\D/g, '');
            this.value = Number(this.value);
        }

猜你喜欢

转载自www.cnblogs.com/wpp281154/p/12758833.html
今日推荐