FluffySaysNo
Петля :
var aInputs = document.getElementsByTagName("input");
for (var i = 0; i < aInputs.length; i += 1)
{
// check for textbox attribute
if (/* oType == "text" */)
{
aInputs[i][/*onchange*/] = ValidateChangeFunction;
aInputs[i][/*onkeydown*/] = ValidateKeyPressFunction;
aInputs[i][/*Event to validate...*/] = ValidateFunction;
}
}
Проверка (не уверен, что все, что вам нужно, поэтому я бросил весь объект из моего старого js-файла) :
var KeyCodes =
{
/// <summary> Object designed to handle various key code identifications. </summary>
IsSpecial : function(oEvent) { return oEvent.ctrlKey || oEvent.altKey; },
IsActionKey : function(oEvent) { return KeyCodes.IsEditKey(oEvent) || KeyCodes.IsCtrlCommand(oEvent); },
IsNumber : function(oEvent) { return KeyCodes.IsActionKey(oEvent) || (((oEvent.which >= 48 && oEvent.which <= 57) || (oEvent.which >= 96 && oEvent.which <= 105)) && oEvent.shiftKey == false); },
IsDecimal : function(oEvent) { return KeyCodes.IsNumber(oEvent) || ((oEvent.which == KeyCodes.PERIOD || oEvent.which == KeyCodes.NUMPAD_DECIMAL) && oEvent.srcElement.value.indexOf(".") == -1); },
IsEditKey : function(oEvent)
{
var bIsEdit = false;
if (this.IsSpecial(oEvent))
return true;
switch (oEvent.which)
{
case this.ENTER :
case this.NUMPAD_ENTER :
case this.BACKSPACE :
case this.TAB :
case this.PAGE_UP :
case this.PAGE_DOWN :
case this.END :
case this.HOME :
case this.DELETE :
case this.INSERT :
case this.LEFT :
case this.RIGHT :
case this.UP :
case this.DOWN :
bIsEdit = true; break;
default :
bIsEdit = false;
}
return bIsEdit;
},
IsCtrlCommand : function(oEvent)
{
var bIsCtrlCommand = false;
if (oEvent.which == 17) // CTRL
return true;
else if (oEvent.ctrlKey)
switch (oEvent.which)
{
case 65: // a
case 67: // c
case 70: // f
case 83: // s
case 86: // v
case 88: // x
case 90: // z
bIsCtrlCommand = true; break;
default :
bIsCtrlCommand = false;
}
return bIsCtrlCommand;
},
Display : function(oKeyCode) { return oKeyCode ? String.fromCharCode(oKeyCode) : ""; },
ESCAPE : 27,
ENTER : 13,
NUMPAD_ENTER : 108,
BACKSPACE : 8,
DELETE : (IsKHTML() ? 127 : 46),
INSERT : 45,
END : 35,
HOME : 36,
PAGE_DOWN : 34,
PAGE_UP : 33,
SPACE : 32,
TAB : 9,
NUMPAD_DECIMAL : 110,
PERIOD : 190,
COMMA : 188,
UP : 38,
DOWN : 40,
LEFT : 37,
RIGHT : 39,
NUMPAD_ADD : 107,
NUMPAD_DIVIDE : 111,
NUMPAD_MULTIPLY : 106,
NUMPAD_SUBTRACT : 109
}