Format number in an HTML5 input tag

后端 未结 3 1514
星月不相逢
星月不相逢 2021-01-18 17:00

This is my input


Is it possible to only allow users to enter

3条回答
  •  礼貌的吻别
    2021-01-18 17:21

    function inputLimiter(e,allow) {
        var AllowableCharacters = '';
    
        if (allow == 'custom'){AllowableCharacters=' 1234567890.';}
    
    
        var k = document.all?parseInt(e.keyCode): parseInt(e.which);
        if (k!=13 && k!=8 && k!=0){
            if ((e.ctrlKey==false) && (e.altKey==false)) {
            return (AllowableCharacters.indexOf(String.fromCharCode(k))!=-1);
            } else {
            return true;
            }
        } else {
            return true;
        }
        
        }
    
    
    

    In Javascript. But this was as far as I got, will just leave this here for awhile, need to handle other stuffs.

提交回复
热议问题