/*只能输入数字和*,不能以0开头 onkeypress='Amount_keypress(this)' */ function Amount_keypress(obj) { var e = window.event || arguments.callee.caller.arguments[0]; var keyCode = e.keyCode; var reg = /^[1-9]d{1,4}$/ if ((obj.value.length == 0) && keyCode == 42) { event.returnValue = true; return; } if (obj.value.length == 0 && keyCode == 48) { event.returnValue = false; return; } if ((keyCode > 47 && keyCode < 58)) { event.returnValue = true; } else { event.returnValue = false; } } /*只能输入数字,小数点后最多2位 onkeypress='price_keypress(this)' */ function price_keypress(obj) { var e = window.event || arguments.callee.caller.arguments[0]; var keyCode = e.keyCode; var reg = /^d+[.]?d{1,2}$/; if (keyCode == 46 || (keyCode >= 48 && keyCode <= 57)) { if (keyCode == 46 && obj.value.indexOf('.') > -1) { event.returnValue = false; return; } if (obj.value.indexOf('.') > -1 && (obj.value.length - obj.value.indexOf('.')) > 2) { event.returnValue = false; return; } event.returnValue = true; } else { event.returnValue = false; } }
.input { 50px; text-align: center; ime-mode:disabled }