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

<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>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值