本文介绍了如何禁用和启用Div元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 请在下面指导我,隐藏和显示DIV元素没有问题,但是点击提交按钮我从asp:RequiredFieldValidator获得错误,因为控件存在于我隐藏的DIV元素中。 br $> b $ b <%@ 页 语言 = C# AutoEventWireup = true CodeFile = IssuerClaimCreationStep1.aspx .cs 继承 = CreateClaim %> < !DOCTYPE html PUBLIC - // W3C // DTD XHTML 1.0 Transitional // EN http://www.w3.or g / TR / xhtml1 / DTD / xhtml1-transitional.dtd > < html xmlns = http://www.w3.org/1999/xhtml > < head runat = server > < title > 创建声明步骤 - 01 < / title > < meta http-equiv = X-UA兼容 content = IE = Edge / > <! - 导入CSS样式 - > < link rel = 样式表 href = Css / SinglePanelStyle.css type = text / css / > <! - 导入JQuery插件 - > < script type = text / jscript src = jquery / jquery-1.9.1.js > < / 脚本 > < script type = text / jscript src = jquery / jquery-ui-1.10.3.js > < / script > < link rel = 样式表 href = jquery / jquery-ui.css type = text / css / > <! - 导入提示插件 - > < script type = text / jscript src = JavaScript / Hint.js > < / script > < link rel = 样式表 href = Css / HintStyle.css type = text / css / > < script type = text / javascript > $( document )。ready( function (){ $( ' #radOurBankATM')。click( function (){ / * 隐藏DDL * / $(' #AcquiringBankListdiv')。css( display, none); / * 设置文本框值* / $( #txtAcquiringBank')。get( 0 )。value = 公司银行; $(' #AcquiringBankdiv')。css( display, block ); }); $(' #radOtherBankATM')。click( function (){ / * 隐藏文本框* / $(' #AcquiringBankdiv')。css( display, none); $(' #AcquiringBankListdiv')。 css( display, block); }); if ($( #radOurBankATM)。is( :checked)){ ValidatorEnable( document .getElementById(' AcqBankListReqFielValid'), false ); ValidatorEnable( document .getElementById(' AcqBankReqFielValid'), true ); } if ($( #radOtherBankATM)。is( :checked) ){ ValidatorEnable( document .getElementById(' AcqBankListReqFielValid'), true ); ValidatorEnable( document .getElementById(' AcqBankReqFielValid'), false ); } }); < / script > < / head > < body > < 表单 id = CreateClaimForm runat = server > < div class = 包装器 > <! - 中间页面Strats Here - > < div class = 主要内容clearfix > < center > <! - 登录面板策略 - &g t; < div class = 面板 > <! - 登录框从此处开始 - > < div class = panel-box > < div id = IssuingBankdiv class = DIVOutLayer runat = server > < label id = lblUserID for = 发行银行 runat = server > 发行银行 < / label > < div class = DIVInnerLayer > < 输入 type = text 名称 = 发行银行 id = txtIssuingBank value = 公司银行 runat = server readonly = readOnly / > <! - < span class =hint>您无法更改发行银行< span class =hint-pointer>< / span>< / span> - > < / div > < div class = DIVInnerLayer > < asp:RequiredFieldValidator ID = UserIDReqFielValid runat = server ControlToValidate = txtIssuingBank 文字 = * ErrorMessage = ValidationGroup = 创建ClaimValidationGroup > < / asp :RequiredFieldValidator > < / div > < / div > < div class = CashWithdrawedATM-div > < label id = lblCurPwd = CashWithdrawedATM runat = server > 现金提取ATM < / label > < div style = white-space:nowrap; > < div style = display:inline; > < asp:RadioButton ID = radOurBankATM GroupName = radioATMGroup 文字 = 我们的(CORP)银行ATM runat = server / > < / div > < div style = display:inline;保证金已删除10% > < asp:RadioButton ID = radOtherBankATM GroupName = radioATMGroup 文本 = 其他银行ATM runat = server / > < / div > < / div > < / div > & lt; div id =\"AcquiringBankdiv\" class=\"DIVOutLayer\" runat=\"server\"> < label id=\"lblAcquiringBank\" for=\"AcquiringBank\" runat=\"server\"> Acquiring Bank </label> <div class=\"DIVInnerLayer\"> <input type=\"text\" id=\"txtAcquiringBank\" runat=\"server\" readonly=\"readonly\" /> <span class=\"hint\">You can't edit<span class=\"hint-pointer\"></span></span> </div> <div class=\"DIVInnerLaye r\"> <asp:RequiredFieldValidator ID=\"AcqBankReqFielValid\" runat=\"server\" ControlToValidate=\"txtAcquiringBank\" Text=\"*\" ErrorMessage=\"\" ValidationGroup=\"CreateClaimValidationGroup\"></asp:RequiredFieldValidator> </div> </div> <div id=\"AcquiringBankListdiv\" class=\"DIVOutLayer\" runat=\"server\"> <label id=\"lblAcquiringBankList\" for=\"AcquiringBankList\" runat=\"server\"> Acquiring Bank </label> <div class=\"DIVInnerLayer\"> <select runat=\"server\" id=\"ddlAcquiringBankList\"> <option value=\"Acquiring Bank\" style=\"color: Gray;\">Please Select Acquiring Bank</option> </select> </div> <div class=\"DIVInnerLayer\"> <asp:RequiredFieldValidator ID=\"AcqBankListReqFielValid\" runat=\"server\" ControlToValidate=\"ddlAcquiringBankList\" Text=\"*\" ErrorMessage=\"\" InitialValue=\"Acquiring Bank\" ValidationGroup=\"CreateClaimValidationGroup\"></asp:RequiredFieldValidator> </div> </div> <div id=\"CusBranchCodediv\" class=\"DIVOutLayer\" runat=\"server\"> <label id=\"lblCusBranchCode\" for=\"CusBranchCode\" runat=\"server\"> Customer Branch Code </label> <div class=\"DIVInnerLayer\"> <asp:TextBox ID =\"txtCusBranchCode\" runat=\"server\" MaxLength=\"4\"></asp:TextBox> <span class=\"hint\">Only numeric [0-9]. Maximum 4 digits. (Ex : 1,0001,01,001)<span class=\"hint-pointer\"></span></span> </div> <div class=\"DIVInnerLayer\"> <asp:RequiredFieldValidator ID=\"RequiredFieldValidator1\" runat=\"server\" ControlToValidate=\"txtCusBranchCode\" Text=\"*\" ErrorMessage=\"\" ValidationGroup=\"CreateClaimValidationGroup\"></asp:RequiredFieldValidator> <asp:CustomValidator ID=\"CusBranchCodeCusValid\" runat=\"server\" Text=\"*\" ErrorMessage=\"Invalid Customer Branch Code\" ControlToValidate=\"txtCusBranchCode\" ValidationGroup=\"CreateClaimValidationGroup\" OnServerValidate=\"CusBranchCodeCusValid_ServerValidate\"></asp:CustomValidator> </div> </div> <div class=\"DIVOutLayer\" id=\"CusBranchNameDiv\" runat=\"server\"> <label id=\"lblCusBranchName\" for=\"CusBranchName\" runat=\"server\"> Customer Branch Name </label> <div class=\"DIVInnerLayer\"> <input type=\"text\" id=\"txtCusBranchName\" runat=\"server\" readonly=\"readonly\" /> <span class=\"hint\">You can't edit this<span class=\"hint-pointer\"></span></span> </div> <div class=\"DIVInnerLayer\"> <asp:RequiredFieldValidator ID=\"RequiredFieldValidator2\" runat=\"server\" ControlToValidate=\"txtCusBranchName\" Text=\"*\" ErrorMessage=\"\" ValidationGroup=\"CreateClaimValidationGroup\"></asp:RequiredFieldValidator> </div> </div> <div id=\"AccountNo-div\" class=\"DIVOutLayer\"> <label id=\"lblAccountNo\" for=\"Account Number\" runat=\"server\"> Account Number </label> <div class=\"DIVInnerLayer\"> <select class=\"AccountType\" id=\"ddlAccountType\" runat=\"server\"> <option value=\"A/C Type\" style=\"color: Gray;\">A/C Type</option> </select> </div> <div class=\"DIVInnerLayer\"> <asp:RequiredFieldValidator ID=\"AccTypeReqFielValid\" runat=\"server\" ControlToValidate=\"ddlAccountType\" ValidationGroup=\"CreateClaimValidationGroup\" InitialValue=\"A/C Type\" Text=\"*\" ErrorMessage=\"\"></asp:RequiredFieldValidator> </div> <div class=\"DIVInnerLayer\"> <select class=\"AccountTypeNo\" id=\"ddlAccountTypeNo\" runat=\"server\"> <option value=\"AccountTypeNo\" style=\"color: Gray;\">A/C Type No</option> </select> </div> <div class=\"DIVInnerLayer\"> <asp:RequiredFieldValidator ID=\"AccTypeNoReqFielValid\" runat=\"server\" ControlToValidate=\"ddlAccountTypeNo\" ValidationGroup=\"CreateClaimValidationGroup\" InitialValue=\"AccountTypeNo\" Text=\"*\" ErrorMessage=\"\"></asp:RequiredFieldValidator> </div> <div class=\"DIVInnerLayer\"> <asp:TextBox ID=\"txtAccountNo \" runat=\"server\" MaxLength=\"6\" Style=\"margin-left: 2%; width: 24.1%;\"></asp:TextBox> <span class=\"hint\">Maximum 6 digits. (Ex : 67,067,0067,00067,000067)<span class=\"hint-pointer\"></span></span> </div> <div class=\"DIVInnerLayer\"> <asp:RequiredFieldValidator ID=\"AccNoReqFielValid\" runat=\"server\" ControlToValidate=\"txtAccountNo\" ValidationGroup=\"CreateClaimValidationGroup\" Text=\"*\" ErrorMes sage=\"\"></asp:RequiredFieldValidator> <asp:CustomValidator ID=\"AccNoCusValid\" runat=\"server\" Text=\"*\" ErrorMessage=\"Invalid Account No\" ControlToValidate=\"txtAccountNo\" ValidationGroup=\"CreateClaimValidationGroup\" OnServerValidate=\"AccNoCusValid_ServerValidate\"></asp:CustomValidator> </div> </div> </div> <!-- signin-box ends here --> <!-- ************************************************************* --> <!-- Error Message Strats Here --> <div class=\"errormsg\" id=\"ErrorMsg\"> <br /> <label id=\"lblErrorMsg\" for=\"ErrorMsg\" runat=\"server\"> * Error Msg </label> </div> <div class=\"errormsg\" id=\"LoginValidSummary-div\"> <asp:ValidationSummary ID=\" LoginValidSummary\" runat=\"server\" HeaderText=\"* Indicates mandatory\" ValidationGroup=\"CreateClaimValidationGroup\" DisplayMode=\"List\" /> </div> <div class=\"errormsg\" id=\"ExceptionMsg-div\"> <label id=\"lblExceptionMsg\" for=\"ExceptionMsg\" runat=\"server\"> * An error has occurred. Please check the log files </label> </div> <!-- Error Message Ends Here --> <!-- ************************************************************* --> <div> <center> <asp:Button ID=\"btnNext\" Text=\"Next\" runat=\"server\" ValidationGroup=\"CreateClaimValidationGroup\" onclick=\"btnNext_Click\" /> </center> </div> </div> <!-- Sign-in Panel Ends here --> </center> </div> <!-- Middle Page Ends Here --> </div> </form> </body> </html> 解决方案 (document).ready(function () {('#radOurBankATM').click(function () { /* Hide DDL */('#AcquiringBankListdiv').css(\"display\", \"none\"); /* Set Text Box Value */Please guide me on below, There is no problem with hide and show DIV element, but while click the submit button i'm getting error from "asp:RequiredFieldValidator" for the controls exist in DIV element which i have hide.<%@ Page Language="C#" AutoEventWireup="true" CodeFile="IssuerClaimCreationStep1.aspx.cs" Inherits="CreateClaim" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>Create Claim Step - 01</title> <meta http-equiv="X-UA-Compatible" content="IE=Edge" /> <!-- Import CSS Styles --> <link rel="Stylesheet" href="Css/SinglePanelStyle.css" type="text/css" /> <!-- Import JQuery Plugins --> <script type="text/jscript" src="jquery/jquery-1.9.1.js"></script> <script type="text/jscript" src="jquery/jquery-ui-1.10.3.js"></script> <link rel="stylesheet" href="jquery/jquery-ui.css" type="text/css" /> <!-- Import Hint Plugins --> <script type="text/jscript" src="JavaScript/Hint.js"></script> <link rel="Stylesheet" href="Css/HintStyle.css" type="text/css" /> <script type="text/javascript"> $(document).ready(function () { $('#radOurBankATM').click(function () { /* Hide DDL */ $('#AcquiringBankListdiv').css("display", "none"); /* Set Text Box Value */ $('#txtAcquiringBank').get(0).value = "Corporation Bank"; $('#AcquiringBankdiv').css("display", "block"); }); $('#radOtherBankATM').click(function () { /* Hide Text Box */ $('#AcquiringBankdiv').css("display", "none"); $('#AcquiringBankListdiv').css("display", "block"); }); if ($("#radOurBankATM").is(":checked")) { ValidatorEnable(document.getElementById('AcqBankListReqFielValid'), false); ValidatorEnable(document.getElementById('AcqBankReqFielValid'), true); } if ($("#radOtherBankATM").is(":checked")) { ValidatorEnable(document.getElementById('AcqBankListReqFielValid'), true); ValidatorEnable(document.getElementById('AcqBankReqFielValid'), false); } }); </script></head><body> <form id="CreateClaimForm" runat="server"> <div class="wrapper"> <!-- Middle Page Strats Here --> <div class="main content clearfix"> <center> <!-- Sign-in Panel Strats here --> <div class="panel"> <!-- signin-box starts here --> <div class="panel-box"> <div id="IssuingBankdiv" class="DIVOutLayer" runat="server"> <label id="lblUserID" for="Issuing Bank" runat="server"> Issuing Bank </label> <div class="DIVInnerLayer"> <input type="text" name="Issuing Bank" id="txtIssuingBank" value="Corporation Bank" runat="server" readonly="readOnly" /> <!-- <span class="hint">You can't change Issuing Bank<span class="hint-pointer"></span></span> --> </div> <div class="DIVInnerLayer"> <asp:RequiredFieldValidator ID="UserIDReqFielValid" runat="server" ControlToValidate="txtIssuingBank" Text="*" ErrorMessage="" ValidationGroup="CreateClaimValidationGroup"></asp:RequiredFieldValidator> </div> </div> <div class="CashWithdrawedATM-div"> <label id="lblCurPwd" for="CashWithdrawedATM" runat="server"> Cash Withdrawed ATM </label> <div style="white-space: nowrap;"> <div style="display: inline;"> <asp:RadioButton ID="radOurBankATM" GroupName="radioATMGroup" Text="Our(CORP) Bank ATM" runat="server" /> </div> <div style="display: inline; margin-removed 10%"> <asp:RadioButton ID="radOtherBankATM" GroupName="radioATMGroup" Text="Other Bank ATM" runat="server" /> </div> </div> </div> <div id="AcquiringBankdiv" class="DIVOutLayer" runat="server"> <label id="lblAcquiringBank" for="AcquiringBank" runat="server"> Acquiring Bank </label> <div class="DIVInnerLayer"> <input type="text" id="txtAcquiringBank" runat="server" readonly="readonly" /> <span class="hint">You can't edit<span class="hint-pointer"></span></span> </div> <div class="DIVInnerLayer"> <asp:RequiredFieldValidator ID="AcqBankReqFielValid" runat="server" ControlToValidate="txtAcquiringBank" Text="*" ErrorMessage="" ValidationGroup="CreateClaimValidationGroup"></asp:RequiredFieldValidator> </div> </div> <div id="AcquiringBankListdiv" class="DIVOutLayer" runat="server"> <label id="lblAcquiringBankList" for="AcquiringBankList" runat="server"> Acquiring Bank </label> <div class="DIVInnerLayer"> <select runat="server" id="ddlAcquiringBankList"> <option value="Acquiring Bank" style="color: Gray;">Please Select Acquiring Bank</option> </select> </div> <div class="DIVInnerLayer"> <asp:RequiredFieldValidator ID="AcqBankListReqFielValid" runat="server" ControlToValidate="ddlAcquiringBankList" Text="*" ErrorMessage="" InitialValue="Acquiring Bank" ValidationGroup="CreateClaimValidationGroup"></asp:RequiredFieldValidator> </div> </div> <div id="CusBranchCodediv" class="DIVOutLayer" runat="server"> <label id="lblCusBranchCode" for="CusBranchCode" runat="server"> Customer Branch Code </label> <div class="DIVInnerLayer"> <asp:TextBox ID="txtCusBranchCode" runat="server" MaxLength="4"></asp:TextBox> <span class="hint">Only numeric [0-9]. Maximum 4 digits. (Ex : 1,0001,01,001)<span class="hint-pointer"></span></span> </div> <div class="DIVInnerLayer"> <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtCusBranchCode" Text="*" ErrorMessage="" ValidationGroup="CreateClaimValidationGroup"></asp:RequiredFieldValidator> <asp:CustomValidator ID="CusBranchCodeCusValid" runat="server" Text="*" ErrorMessage="Invalid Customer Branch Code" ControlToValidate="txtCusBranchCode" ValidationGroup="CreateClaimValidationGroup" OnServerValidate="CusBranchCodeCusValid_ServerValidate"></asp:CustomValidator> </div> </div> <div class="DIVOutLayer" id="CusBranchNameDiv" runat="server"> <label id="lblCusBranchName" for="CusBranchName" runat="server"> Customer Branch Name </label> <div class="DIVInnerLayer"> <input type="text" id="txtCusBranchName" runat="server" readonly="readonly" /> <span class="hint">You can't edit this<span class="hint-pointer"></span></span> </div> <div class="DIVInnerLayer"> <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtCusBranchName" Text="*" ErrorMessage="" ValidationGroup="CreateClaimValidationGroup"></asp:RequiredFieldValidator> </div> </div> <div id="AccountNo-div" class="DIVOutLayer"> <label id="lblAccountNo" for="Account Number" runat="server"> Account Number </label> <div class="DIVInnerLayer"> <select class="AccountType" id="ddlAccountType" runat="server"> <option value="A/C Type" style="color: Gray;">A/C Type</option> </select> </div> <div class="DIVInnerLayer"> <asp:RequiredFieldValidator ID="AccTypeReqFielValid" runat="server" ControlToValidate="ddlAccountType" ValidationGroup="CreateClaimValidationGroup" InitialValue="A/C Type" Text="*" ErrorMessage=""></asp:RequiredFieldValidator> </div> <div class="DIVInnerLayer"> <select class="AccountTypeNo" id="ddlAccountTypeNo" runat="server"> <option value="AccountTypeNo" style="color: Gray;">A/C Type No</option> </select> </div> <div class="DIVInnerLayer"> <asp:RequiredFieldValidator ID="AccTypeNoReqFielValid" runat="server" ControlToValidate="ddlAccountTypeNo" ValidationGroup="CreateClaimValidationGroup" InitialValue="AccountTypeNo" Text="*" ErrorMessage=""></asp:RequiredFieldValidator> </div> <div class="DIVInnerLayer"> <asp:TextBox ID="txtAccountNo" runat="server" MaxLength="6" Style="margin-left: 2%; width: 24.1%;"></asp:TextBox> <span class="hint">Maximum 6 digits. (Ex : 67,067,0067,00067,000067)<span class="hint-pointer"></span></span> </div> <div class="DIVInnerLayer"> <asp:RequiredFieldValidator ID="AccNoReqFielValid" runat="server" ControlToValidate="txtAccountNo" ValidationGroup="CreateClaimValidationGroup" Text="*" ErrorMessage=""></asp:RequiredFieldValidator> <asp:CustomValidator ID="AccNoCusValid" runat="server" Text="*" ErrorMessage="Invalid Account No" ControlToValidate="txtAccountNo" ValidationGroup="CreateClaimValidationGroup" OnServerValidate="AccNoCusValid_ServerValidate"></asp:CustomValidator> </div> </div> </div> <!-- signin-box ends here --> <!-- ************************************************************* --> <!-- Error Message Strats Here --> <div class="errormsg" id="ErrorMsg"> <br /> <label id="lblErrorMsg" for="ErrorMsg" runat="server"> * Error Msg </label> </div> <div class="errormsg" id="LoginValidSummary-div"> <asp:ValidationSummary ID="LoginValidSummary" runat="server" HeaderText="* Indicates mandatory" ValidationGroup="CreateClaimValidationGroup" DisplayMode="List" /> </div> <div class="errormsg" id="ExceptionMsg-div"> <label id="lblExceptionMsg" for="ExceptionMsg" runat="server"> * An error has occurred. Please check the log files </label> </div> <!-- Error Message Ends Here --> <!-- ************************************************************* --> <div> <center> <asp:Button ID="btnNext" Text="Next" runat="server" ValidationGroup="CreateClaimValidationGroup" onclick="btnNext_Click" /> </center> </div> </div> <!-- Sign-in Panel Ends here --> </center> </div> <!-- Middle Page Ends Here --> </div> </form></body></html> 解决方案 (document).ready(function () {('#radOurBankATM').click(function () { /* Hide DDL */('#AcquiringBankListdiv').css("display", "none"); /* Set Text Box Value */ 这篇关于如何禁用和启用Div元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-10 19:37