working with numeric input field in js

三世轮回 提交于 2019-12-08 11:29:25

问题


i have a form in wich i have several input... one of them should be a number input type.

i use this code to get only numeric input in a input type.

<script type="text/javascript">
    function isNumberKey(evt){
        var charCode = (evt.which) ? evt.which : event.keyCode
        if ((charCode > 31) && (charCode < 48 || charCode > 57))
            return false;
        return true;
    }
</script>

but i need another features that i still not able to "create"...

i have an input type (example : ) and onkeyup event i call this function (isNumberKey - allowing only numeric input). in case the number wrote is composed by 4 or more numbers i'd like to return (on the same input) the string with the dot notation every 3 number... ex. 900->900 but 1234 -> 1.234 or 15000 -> 15.000.


回答1:


This might be the answer of your question to make the input strictly numeric and allow .(dot) with it.
Make your show the number insert with a dot every 3 number, like this : 100000 -> 100.000. how? part of question clear

UPDATE
Though not a perfect solution try this fiddle
Reference



来源:https://stackoverflow.com/questions/21984248/working-with-numeric-input-field-in-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!