在前台用 JS 清空 服务器控件里面的值 剩余字数验证 邮箱验证 非空验证

 
注意 DIV 的选取 更改
 
function countChar(textareaName, counter) {
    var cou = document.getElementById("mContent").value.length;
    document.getElementById(counter).innerHTML = 300 - cou;
    if (cou > 299) {
        document.getElementById("mContent").value = document.getElementById("mContent").value.substring(0, 299);
        alert("超出长度");
    }
}
 
        function clearControl() {
            var Input = prizeshow_div.getElementsByTagName("input");
 
            for (var i = 0; i < Input.length; i++) {
                if (Input[i].type == "text") {
 
                    Input[i].value = "";
                }
            }
            return false;
        }
        function clearControl2() {
            var textarea = prizeshow_div.getElementsByTagName("textarea");
 
            for (var i = 0; i < textarea.length; i++) {
 
                if (textarea[i].name == "mContent") {
 
                    textarea[i].value = "";
                }
            }
            return false;
        } 

 

 

页面

 

<div class="prizeshow_divc">
           <dl>
               <dt><span>*</span>企业名:</dt>
               <dd>
                   <asp:TextBox ID="mCompany" class="prizeshow_divinp
rizeshow_wid1" runat="server"></asp:TextBox>
                   <asp:RequiredFieldValidator ID="valrTel" runat="server" ControlToValidate="mCompany"
                       Display="Dynamic" ErrorMessage="公司名不能为空!" Font-Size="Small" SetFocusOnError="True"></asp:RequiredFieldValidator>
               </dd>
           </dl>
           <dl>
               <dt><span>*</span>姓名:</dt>
               <dd>
                   <asp:TextBox ID="mName" class="prizeshow_divinp prizeshow_wid1" runat="server"></asp:TextBox>
                   <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="mName"
                       Display="Dynamic" ErrorMessage="姓名不能为空!" Font-Size="Small" SetFocusOnError="True"></asp:RequiredFieldValidator>
               </dd>
           </dl>
           <dl>
               <dt><span>*</span>邮件地址:</dt>
               <dd>
                   <asp:TextBox ID="mMail" class="prizeshow_divinp prizeshow_wid1" runat="server"></asp:TextBox>
                   <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="mMail"
                       Display="Dynamic" ErrorMessage="邮件地址不能为空!" Font-Size="Small" SetFocusOnError="True"></asp:RequiredFieldValidator>
                   <asp:RegularExpressionValidator ID="RegularExpressionValidator1" ControlToValidate="mMail"
                       EnableClientScript="true" ValidationExpression="^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$"
                       runat="server" Display="Dynamic" ErrorMessage="邮件格式不正确!"></asp:RegularExpressionValidator>
               </dd>
           </dl>

 

<dd>
    <textarea class="prizeshow_divinp prizeshow_wid2" runat="server" id="mContent" name="msgbox"
        onkeydown='countChar("msgbox","counter");' onkeyup='countChar("msgbox","counter");'
        rows="5" style="overflow: auto"></textarea>
    <br />
    <span class="prizeshow_divcspan1">(300字以内,还能输入<span id="counter" class="prizeshow_divcspan2"><em>300</em></span>字。)</span>
    <br />
    <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="mContent"
        Display="Dynamic" ErrorMessage="咨询内容不能为空!" Font-Size="Small" SetFocusOnError="True"></asp:RequiredFieldValidator>
</dd>
 
<input type="button" value="取消" onclick="prizeclosediv()" onclick="btnCancel_Click" />

你可能感兴趣的:(服务器)