html5中input type=number时如何监听去除用户输入的+,-号?

2025-04-04 19:26:07
推荐回答(1个)
回答1:

var input = document.getElementById('text');

input.oninput = function (event) {
    var value = this.value;
    var regx = /\+|\-/i;

    if(regx.test(value)) {
        this.value = value.substring(0, value.length-1);
    }
};