<span style="font-family:微软雅黑;font-size:14px;color:#000000;font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none;">javascrip有一个isNaN(val)方法,可以用于判断val是否是一个纯数字,如果是数字返回false,试过不是数字返回True。</span>
<!DOCTYPE html>
<html>
<head>
<title>2.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
<script >
function ischeckNum()
{
var num = document.getElementById('isnum').value;
if( num )
{
if( !isNaN( num ) )
{
alert('是数字');
return false;
}
else
{
alert('你输入的数据不是数字');
myfm.isnum.select();
return false;
}
}
else
{
alert('需输入内容');
myfm.isnum.focus();
}
}
</script>
</head>
<body>
<form name="myfm" method="post" action="">
<label>
<input type="text" name="isnum" id="isnum">
</label>
<label>
<input type="button" name="Submit" value="检测是否为数字" onClick="ischeckNum();">
</label>
</form>
</body>
</html>
判断文本框输入内容是否为数字,
最新推荐文章于 2021-11-25 16:29:08 发布