VS2005+ASP.NET2.0,完整代码贴上,我这方面新手,所以碰到问题一上午没解决。请大家帮帮我!
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><%-- 实验发现html/asp中很容易成功是因为后面的form是用name,而aspx中form要用id--%><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>用javascript验证输入框空白</title>
    <script type ="text/javascript">
    function check_Null()
    {         
        //var Forms=document.getElementById("form1").elements;                  if (document.form1.user_id.value=="" || document.form1.user_id.value==null)
    {
    alert("用户名不能为空!");
    return false;
    }
    if (document.form1.password.value=="" || document.form1.password.value==null)
    {
    alert("密码不能为空!");
         return false;
    }
    return true;
     }     
 </script>   
</head>
<body>
    <form id="form1" method="post" action="Login.aspx" onsubmit="return check_Null()">  
        <table border="0" cellpadding="0" cellspacing="1" style="background-color: #0000FF; border-color: #FFFFFF; margin:0 auto" width="85%">
            <tr style="background-color: #E1F3F4; height: 40px">
                <td valign="middle" style="background-color:#FFFFFF">                
                    用户名<input type="text" name="user_id" size="13" class="input" />
    密码<input type="PassWord" name="password" size="13" class="input" />
    <input class="inputbutton" type="submit" value="登 录" name="Submit" />      
                </td>                
            </tr>            
        </table>    
    </form>
</body>
</html>

解决方案 »

  1.   

    document.form1.user_id.value==""
    ==》
    document.getElementById("user_id").value==""
      

  2.   


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><%-- 实验发现html/asp中很容易成功是因为后面的form是用name,而aspx中form要用id--%><html xmlns="http://www.w3.org/1999/xhtml" >
    <head id="Head1" runat="server">
        <title>用javascript验证输入框空白</title>
        <script type ="text/javascript">
            function check_Null() {
                if (document.getElementById("txtUid").value == "") {
                    alert("用户名不能为空!");
                    return false;
                }
                if (document.getElementById("txtPwd").value == "") {
                    alert("密码不能为空!");
                    return false;
                }
                return true;
            }        
         </script>      
    </head>
    <body>
        <form id="form1" method="post" action="Login.aspx" onsubmit="return check_Null()">  
            <table border="0" cellpadding="0" cellspacing="1" style="background-color: #0000FF; border-color: #FFFFFF; margin:0 auto" width="85%">
                <tr style="background-color: #E1F3F4; height: 40px">
                    <td valign="middle" style="background-color:#FFFFFF">                
                        用户名<input type="text" id="txtUid" name="user_id" size="13" class="input" />
                        密码<input type="password" id="txtPwd" name="password" size="13" class="input" />
                        <input class="inputbutton" type="submit" value="登 录" name="Submit" />                     
                    </td>                
                </tr>            
            </table>    
        </form>
    </body>
    </html>
      

  3.   

    谢谢各位,不仅form改成id,input里也要改id才行。