js 限制文本只能输入数字
时间:2011-04-14 来源:X龙
function limitNumber(event)
{
var keyCode = event.keyCode | event.charCode;
if (!((keyCode > 47 && keyCode < 58)
|| (keyCode > 95 && keyCode < 106)
|| keyCode == 13
|| keyCode == 8))
{
event.returnValue = false;
}
}
function setLimitNumberInput(id)
{
var objTarget = document.getElementById(id);
if (objTarget == null)
{
return;
}
objTarget.onkeydown = function()
{
limitNumber(event);
};
objTarget.onpaste = function()
{
limitNumber(event);
};
objTarget.ondrop = function()
{
limitNumber(event);
};
}
{
var keyCode = event.keyCode | event.charCode;
if (!((keyCode > 47 && keyCode < 58)
|| (keyCode > 95 && keyCode < 106)
|| keyCode == 13
|| keyCode == 8))
{
event.returnValue = false;
}
}
function setLimitNumberInput(id)
{
var objTarget = document.getElementById(id);
if (objTarget == null)
{
return;
}
objTarget.onkeydown = function()
{
limitNumber(event);
};
objTarget.onpaste = function()
{
limitNumber(event);
};
objTarget.ondrop = function()
{
limitNumber(event);
};
}
相关阅读 更多 +