ATM样式的小数位 [英] ATM style decimal places

查看:84
本文介绍了ATM样式的小数位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力获取旧代码从2003年开始工作.我正在尝试复制ATM样式的十进制文本框.这段代码声称对某人有用,但是我在实现它时遇到了麻烦.

I'm working on getting an old piece of code working, from 2003. I'm trying to replicate an ATM style decimal textbox. This code claims to have worked for someone, but I am having trouble implementing it.

也许有人有更好的方法来实现这一目标?也许在jQuery中?

Maybe someone has a better way of achieving this? Maybe in jQuery?

推荐答案

这就是我要解决的方法: http ://jsfiddle.net/77bMx/86/

This is how I would solve it: http://jsfiddle.net/77bMx/86/

  • 处理数字键盘输入和标准数字键
  • 使用退格键
  • 如果您设法以某种方式产生非法输入(例如,退格过多),将恢复为0.00

基本思想是截获对框的任何输入,确保其类型正确(数字或退格键),然后将其添加到后备存储字符串(var input),然后格式化该字符串正确显示.用户永远不会直接在文本框中输入任何内容,因为我在事件处理程序的末尾使用了return false.

The basic idea is to intercept any input to the box, make sure it's of the correct type (a number, or a backspace) and then add it to a backing storage string (var input), and then format that string to display correctly. The user never directly enters anything into the text box, since I use return false at the end of the event handler.

这篇关于ATM样式的小数位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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