日期:2014-05-17  浏览次数:20509 次

求教一个ASP.net页面验证的问题!!
<script type="text/javascript">
    function StuNameYZ() {
        var myStuName = document.getElementById("<%=txtStuName.ClientID %>").value;
        if (myStuName == "") {
            alert('用户名不能为空');
            return false;
        }
        if (myStuName.value.length < 8 || myStuName.value.length > 16) {
            alert("用户名长度不规范!");
            return false;
        }
     }
</script>
<body>
    <form id="form1" runat="server">
    <div>
        <table>
            <tr>
                <td align="right">姓名:</td>
                <td>
                    <asp:TextBox ID="txtStuName" runat="server" ></asp:TextBox></td>
            </tr> 
            <tr>
                <td align="right">年龄:</td>
                <td>
            <asp:TextBox ID="txtStuAge" runat="server"></asp:TextBox></td></tr>
             <tr>
                <td colspan="2" align="center"> 
                    <asp:Button ID="btnAdd" runat="server" Text="添加" onclick="btnAdd_Click" OnClientClick="StuNameYZ"
                        style="height: 21px" /></td>