您的位置:首页 > Web前端 > JavaScript

判断文本框输入内容是否为数字,

2014-10-03 20:08 344 查看
<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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息