shenma 发表于 2011-11-7 15:23:25

2个小的知识点,供初学者参考

1.js判断是否是数字的函数:isNaN() 。
   NaN 表示表达式 不是数字。

   if( isNaN(age.value))
    {
      alert('这不是一个数字');
      return false;
    }

2.判断单选按钮是否被选中,是用 checked属性,而不是selected。比如说,判断性别输入框的

var boy   = document.getElementById('boy');
var girl       = document.getElementById('girl');
if(!boy.checked && !girl.checked)
    {
      alert('请输入您的性别');
      return false;
    }

页: [1]
查看完整版本: 2个小的知识点,供初学者参考