jquery控制input只能輸入金額
阿新 • • 發佈:2018-11-15
例子表單:
[html] view plain copy
- <input type="text" name="input1" id="input1" value="" />
- <input type="text" name="input2" id="input2" value="" />
- <input type="text" name="input3" id="input3" value="" />
js程式碼:
[javascript] view plain copy
- $(document).ready(function(){
- bindKeyEvent($("#input1"
- bindKeyEvent($("#input2"));
- bindKeyEvent($("#input3"));
- });
- function bindKeyEvent(obj){
- obj.keyup(function () {
- var
- var txt = '';
- if (reg != null) {
- txt = reg[0];
- }
- $(this).val(txt);
- }).change(function () {
- $(this).keypress();
- var v = $(this).val();
- if (/\.$/.test(v))
- {
- $(this).val(v.substr(0, v.length - 1));
- }
- });
- }