javascript 如何使用货币掩码自动格式化输入数字(离子)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34096872/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How auto format input number with currency mask (Ionic)
提问by Willian Custódio
I need to create a currency mask (right to left) in a input=number of my mobile app (Ionic + Cordova). If the user enter with 123456 value, the input should be 1.234,56 (adding "," and "." automatically).
我需要在我的移动应用程序(Ionic + Cordova)的 input=number 中创建一个货币掩码(从右到左)。如果用户输入 123456 值,则输入应为 1.234,56(自动添加“,”和“.”)。
I don't know how to do this with HTML and Javascript.
我不知道如何用 HTML 和 Javascript 做到这一点。
Anybody help me?
有人帮我吗?
Noting that input type should be "number", to show only numeric keyboard in device.
请注意,输入类型应为“数字”,以仅显示设备中的数字键盘。
Sorry my poor english
对不起我可怜的英语
回答by Kiramishima
look at this angular modules and directives:
看看这个角度模块和指令:
http://aguirrel.github.io/ng-currency/
http://aguirrel.github.io/ng-currency/
jsfiddle.net/odiseo/dj6mX/
jsfiddle.net/odiseo/dj6mX/
回答by Crisboot
I know your pain, I've seen a couple of solutions:
我知道你的痛苦,我已经看到了几个解决方案:
Option A:Build custom directive to hide the real box, and put a fake one on top. Just built a proof of concept demo: http://play.ionic.io/app/e3547f0f6b05
Option B:Build your own numpad like basically MobiScroll (some paid library) does: http://demo.mobiscroll.com/numpad/currency/(works ok with angular and ionic) Update: also check this demo: http://demo.mobiscroll.com/numpad/variablefraction/
选项 A:构建自定义指令来隐藏真实的盒子,并在上面放一个假的。刚刚构建了一个概念证明演示:http: //play.ionic.io/app/e3547f0f6b05
选项 B:像基本上 MobiScroll(一些付费库)那样构建你自己的数字键盘:http://demo.mobiscroll.com/numpad/currency/( 适用于 angular 和 ionic) 更新:也检查这个演示:http:// demo.mobiscroll.com/numpad/variablefraction/
回答by Maxim Goncharuk
Look at this plugin for jQuery jquery-numberformatter:
看看这个 jQuery jquery-numberformatter插件:
$(this).parseNumber({format:"#,###.00", locale:"us"});