2个回答
2013-11-06
展开全部
用JS更好<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=" http://www.w3.org/1999/xhtml">
<head>
<title> new document </title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta name="generator" content="editplus" />
<meta name="author" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<script type="text/javascript">
<!--
function checknum(obj)
{
regx=/[^\d]/g; //验证数字(非数字检验正则表达式);
if(regx.test(obj.value))
{
alert("请在输入框内输入纯数字");
return false;
}
}
//-->
</script>
</head> <body>
<input type="text" id="num" onkeyup="checknum(this)"/>
</body>
</html>
<html xmlns=" http://www.w3.org/1999/xhtml">
<head>
<title> new document </title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta name="generator" content="editplus" />
<meta name="author" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<script type="text/javascript">
<!--
function checknum(obj)
{
regx=/[^\d]/g; //验证数字(非数字检验正则表达式);
if(regx.test(obj.value))
{
alert("请在输入框内输入纯数字");
return false;
}
}
//-->
</script>
</head> <body>
<input type="text" id="num" onkeyup="checknum(this)"/>
</body>
</html>
2013-11-06
展开全部
用js不好吗》把那个文本框的值转成int的,用try catch包围,
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询