if(s.value == null || s.length ==0){
    alert("不能为空!");
    return false;
}

解决方案 »

  1.   

    <input type="text" id="txtUserName">if(txtUserName==""){
        alert("用户名称不能为空!");
        txtUserName.focus();
        return false;
    }
      

  2.   

    <script language="javascript">
    <!--
    function check(thisform){
     if(thisform.username.value==""){
       alert("sorry,username can't be blank");
       return false;
      }
    return true;
    }
    //-->
    </script><form action="http://www.sina.com.cn" method="post" onsubmit="return check(document.frm01);" name="frm01>
     <input type="text" name="username">
    <input type="submit" value="submit">
    </form>
      

  3.   

    <script>
    function checktext(){
    if(document.tttt.textarea.value=="")
    {     alert("请填写您的留言内容!!");
     document.tttt.textxareaa.focus();
     return false;
    }
    </script>
    然后在form里加上
    <form name="from1 action="..." method="post" onsubmit="return checktext();" >
      

  4.   

    document.tttt.textxareaa.focus -> document.from1.textxareaa.focus
      

  5.   

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <script language="javaScript">
    function checkit()
    {
    if(document.form1.s.value =="" ||document.form1.s.length ==0){
        alert("不能为空!");
        return false;
    }
    }
    </script>
    <title>无标题文档</title></head><body>
    <form name="form1" action="" method="post">
    姓名:<input type="text" name="s" >
    <input type="submit" name="go" value="提交" onClick="return(checkit());">
    </form>
    </body>
    </html>
      

  6.   

    <html><head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <meta name="GENERATOR" content="Microsoft FrontPage 4.0">
    <meta name="ProgId" content="FrontPage.Editor.Document">
    <title>New Page 1</title>
    </head>
    <form name="frm1" method="post" action="">
    <body>
    <input name="a" type="text">
    <p>
    <a onclick ="vbscript:checkform" href="#" class="button">提交</a>
    </form> 
    </body>
    </html>
    <script language="vbscript">
    <!--
    sub checkform()
    if frm1.a.value="" then
    msgbox "不能空,请填写",vbExclamation,""
    frm1.a.focus()
    exit sub
    end if
    end sub
    -->
    </script>
      

  7.   

    <html><head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <meta name="GENERATOR" content="Microsoft FrontPage 4.0">
    <meta name="ProgId" content="FrontPage.Editor.Document">
    <title>New Page 1</title>
    </head>
    <form name="frm1" method="post" action="">
    <body>
    <input name="a" type="text">
    <p>
    <input type="button" value="保存(S)" accesskey="S" id=submit1 name=submit1 onclick="subcheck()">
    </form> 
    </body>
    </html>
    <script LANGUAGE="javascript">
    <!--
    function subcheck(){
    a=new String(document.all.a.value)
    if("$"+a=="$"||"$"+a=="$undefined"){
    alert("请输入内容!");
    document.all.a.focus()
    return false
    }
        document.frm1.submit()
    }//-->
    </script>