js

function checkRate(input){     var re = /^[0-9]+.?[0-9]*$/;        if(input.match(re))
         {
        return true;
         }
        else
         {
        return false;
         }
}
function checkNull()
{    var title=document.getElementById("txt_title").value;
    
    var wname=document.getElementById("txt_wname").value;
    var catamod=document.getElementById("txt_catamod").value;
     var conmod=document.getElementById("txt_conmod").value;
     var sort=document.getElementById("txt_sort").value;
    if(title=="")
    {
        alert("标题不能为空");
         document.getElementById("txt_title").focus();
        return false;
    }
    if(checkRate(sort).value)==false)
    {
        alert("排序必须为数字");
         document.getElementById("txt_sort").focus();
        return false;
    } 
     if(wname=="")
    {
        alert("文件夹名不能为空");
        document.getElementById("txt_wname").focus();
        return false;
    }
     if  (catamod=="")
    {
         alert("栏目模板不能为空");
         document.getElementById("txt_catamod").focus();
        return false;
    }
    if  (conmod=="")
    {
         alert("内容模板不能为空");
         document.getElementById("txt_conmod").focus();
        return false;
    }
      
} 点击添加时别的非空都提示错误,但排序输入字母还是不能提示要输入数字?

解决方案 »

  1.   

    if(checkRate(sort)==false)
        {
            alert("排序必须为数字");
             document.getElementById("txt_sort").focus();
            return false;
        } 
    发错了,这个后面没有.value
      

  2.   

    if (isNaN(input.value)) {
                        alert('数量只能输出数字!');
                        input.focus();
                        return;
                    }
      

  3.   


      if(checkRate(sort) == false)
      {
      alert("排序必须为数字");
      document.getElementById("txt_sort").focus();
      return false;
      }