要求:
-
- 一个输入框,只可以输入数字或者小数点,其他字符不显示;
- 整数部分最多输入三位;
- 小数部分最多输入一位。
代码:
1: <html>
2: <head>
3: <script language=javascript>
1:
2: function Limite(object)
3: {
4: if(isNaN(object.value))
5: {
6: DoSubString(object);
7: }
8: else
9: {
10: var index = object.value.indexOf('.');
11: if(index > 0)
12: {
13: if(object.value.length > index + 2)
14: DoSubString(object);
15: }
16: else
17: {
18: var IValue = parseInt(obaject.value);
19: if (IValue < 0 || IValue >=1000)
20: DoSubString(object);
21: }
22: }
23: }
24: function DoSubString(object)
25: {
26: object.value=object.value.substring(0,object.value.length-1);
27: }
</
script
>
4: </head>
5:
6: <body>
7: <input onpropertychange="Limite(this)" maxlength="5" name="amount" />
8: </body>
9: </html>
只能输入数字,且范围在0.0~999.9之间,小数只能输入一位,整数最多3位,允许没有小数。