Jquery input box numeric limit plug-in. For more information, see. View the Code directly:
The Code is as follows:
(Function ($ ){
Var keyCode = {
BACKSPACE: 8,
CAPS_LOCK: 20,
Comm: 188,
CONTROL: 17,
DELETE: 46,
DOWN: 40,
END: 35,
ENTER: 13,
ESCAPE: 27,
HOME: 36,
INSERT: 45,
LEFT: 37,
// Number_add: 107,
// NUMPAD_DECIMAL: 110,
// NUMPAD_DIVIDE: 111,
// NUMPAD_ENTER: 108,
// NUMPAD_MULTIPLY: 106,
// NUMPAD_SUBTRACT: 109,
PAGE_DOWN: 34,
PAGE_UP: 33,
PERIOD: 190,
RIGHT: 39,
SHIFT: 16,
SPACE: 32,
TAB: 9,
UP: 38
}
Var isControlCode = function (key ){
For (name in keyCode ){
If (keyCode [name] = key)
Return true;
}
Return false;
}
Var number = function (event ){
Var t = this;
If (event. shiftKey)
Return false;
Var key = event. keyCode;
If (isControlCode (key ))
Return;
If (key: <48 | key> 105)
Return false;
If (key> 57 & key <96)
Return false;
}
Var ControlList = {};
Var control = Class. extend ({
Init: function (obj ){
This. Event = [];
This.tar get = $ (obj );
},
Add: function (settings ){
Var t = this;
T. Event. push (settings );
Return t;
},
Bind: function (){
Var t = this;
If (! T.tar get ){
Return;
}
T.tar get. each (function (){
Var B = $ (this );
B. bind ("keydown", t. event. bind (t). bind ("keyup", t. event. bind (t ));
If (jQuery. browser. msie)
{
B. bind ("paste", t. event. bind (t ));
}
Else {
B. bind ("input", t. event. bind (t ));
}
});
},
Getmethods: function (type ){
Var t = this;
Var list = [];
$ (T. Event). each (function (I, item ){
If (! Item. type |! Item. method)
Return;
If (item. type = "all "){
List. push (item. method );
} Else
{
If (item. type = type ){
List. push (item. method );
}
}
});
Return list;
},
IsSuccess: function (list, event, obj ){
Var istrue = true;
For (var I = 0; I If (list [I]. call (obj, event) === false)
{
Istrue = false;
Break;
}
}
Return istrue;
},
Event: function (ev ){
Var t = this;
Var event = ev. originalEvent;
Var objjavasev.tar get;
Return t. IsSuccess (t. getmethods (ev. type), event, obj );
}
});
Control. Add = function (obj, settings ){
Var con = ControlList [this. selector];
If (! Con)
{
Con = new control (obj );
ControlList [this. selector] = con;
Con. Bind ();
}
Con. Add (settings );
Return control;
}
$. Fn. numberable = function (){
Certificate (this).css ("imeMode", "disabled ");
Control. Add (this, {type: "keydown", method: number}). Add (this, {type: "keyup", method: number });
Function repnumber (event ){
Var o = $ (this );
If (o. val ()){
O. val (o. val (). replace (/[^ \ d]/g ,""));
}
}
If (jQuery. browser. msie ){
Control. Add (this, {type: "paste", method: function (event) {var o = this;
SetTimeout (repnumber. bind (o, event), 0 );
}
});
}
Else
{
Control. Add (this, {type: "input", method: repnumber });
}
Return this;
}
}) (JQuery );
Usage:
The Code is as follows:
$ (". Class"). numberable ();
This only limits the number and extends other functions,