在js中使用数字输入字段 [英] working with numeric input field in js

查看:91
本文介绍了在js中使用数字输入字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表格,我有几个输入... 其中之一应该是数字输入类型.

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"...

我有一个输入类型(例如:),并且onkeyup事件我调用了此函数(isNumberKey-仅允许数字输入). 如果写入的数字由4个或更多数字组成,我想每3个数字返回(在同一输入上)带有点符号的字符串...例如. 900-> 900,但1234-> 1.234或15000-> 15.000.

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.

推荐答案

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
虽然不是一个完美的解决方案,但
试试这个小提琴
参考

UPDATE
Though not a perfect solution try this fiddle
Reference

这篇关于在js中使用数字输入字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆