<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>数字输入检查</title>
<script type="text/javascript" language="javascript">
function KeyPress(objTR)
{//只允许录入数据字符 0-9 ,小数点,负号
//var objTR = element.document.activeElement;
var txtval=objTR.value;
var key = event.keyCode;
//alert(key);
if((key < 48||key > 57)&&key != 46&&key !=45)
{
event.keyCode = 0;
}
else
{
if(key == 46)
{
if(txtval.indexOf(".") != -1||txtval.length == 0)
event.keyCode = 0;
}
else if(key==45)//如果不需要输入负号把这一段拿掉
{
if(txtval.indexOf("-")!=-1||txtval.length != 0)
{
event.keyCode = 0;
}
}
}