在这里,我添加了 asp.net 代码和全局变量以及元素的 jquery 条件,这段代码对我来说很好,但我想简化这段代码。有人可以帮忙吗?
ASP.NET
<div class="toggle_container">
<p>
<asp:HiddenField ID="hdnIsSwipe" runat="server" />
<asp:Label ID="lblPaymentType" runat="server" Text="<span>*</span> Payment Type"
AssociatedControlID="ddlPaymentType"></asp:Label>
<asp:DropDownList ID="ddlPaymentType" runat="server">
</asp:DropDownList>
</p>
<p>
<asp:Label ID="lblAccountNumber" runat="server" Text="<span>*</span> Account Number"
AssociatedControlID="txtAccountNumber"></asp:Label>
<asp:TextBox ID="txtAccountNumber" runat="server" MaxLength="17" Style="width: 155px;"></asp:TextBox>
<asp:HiddenField ID="hdnAccountNo" runat="server" />
<asp:LinkButton ID="btnSwipe" runat="server" CausesValidation="false" OnClientClick="tb_show('Swipe','#TB_inline?height=155&width=300&inlineId=hiddenModalContent&modal=false');return false;"
Visible="true" Text="Swipe" CssClass="btnSwipe">
</asp:LinkButton>
<input id="btnClear" type="button" class="btnClear" name="Click and clear Account Data" />
</p>
<p>
<asp:Label ID="lblAmount" runat="server" Text="<span>*</span> Amount" AssociatedControlID="txtAmount"></asp:Label><asp:TextBox
ID="txtAmount" runat="server" MaxLength="8"></asp:TextBox>
</p>
<p>
<asp:Label ID="lblCVV2" runat="server" Text="CVV2" AssociatedControlID="txtCVV2"></asp:Label><asp:TextBox
ID="txtCVV2" runat="server" MaxLength="4"></asp:TextBox></p>
<p>
<asp:Label ID="lblReferenceNumber" runat="server" Text="Reference Number" AssociatedControlID="txtReferenceNumber"></asp:Label><asp:TextBox
ID="txtReferenceNumber" runat="server" MaxLength="50"></asp:TextBox></p>
<p>
<asp:Label ID="lblSaleTaxAmount" runat="server" Text="<span>*</span> Sale Tax Amount"
AssociatedControlID="txtSaleTaxAmont">
</asp:Label><asp:TextBox ID="txtSaleTaxAmont" runat="server" MaxLength="10"></asp:TextBox></p>
<p>
<asp:Label ID="lblPoNumber" runat="server" Text="<span>*</span> PO Number" AssociatedControlID="txtPoNumber">
</asp:Label><asp:TextBox ID="txtPoNumber" runat="server" MaxLength="20"></asp:TextBox></p>
<p>
<asp:Label ID="lblTaxType" runat="server" Text="<span>*</span> Tax Type" AssociatedControlID="ddlTaxType"></asp:Label>
<asp:DropDownList ID="ddlTaxType" runat="server">
</asp:DropDownList>
</p>
</div>
全局变量
var lblSaleTaxAmount = '#<%=lblSaleTaxAmount.ClientID %>';
var txtSaleTaxAmont= '#<%=txtSaleTaxAmont.ClientID %>';
var lblPoNumber = '#<%=lblPoNumber.ClientID %>';
var txtPoNumber= '#<%=txtPoNumber.ClientID %>';
var lblTaxType = '#<%=lblTaxType.ClientID %>';
var ddlTaxType ='#<%=ddlTaxType.ClientID %>';
jQuery代码
$(ddlPaymentType).change(function(){
if($(ddlPaymentType).val()=='1' || $(ddlPaymentType).val()=='-1' )
{
$(lblSaleTaxAmount).hide();
$(txtSaleTaxAmont).hide();
$(lblPoNumber).hide();
$(txtPoNumber).hide();
$(lblTaxType).hide();
$(ddlTaxType).hide();
$("label[for='ContentSection_txtSaleTaxAmont']").hide();
$("label[for='ContentSection_txtPoNumber']").hide();
}
else
{
$(lblSaleTaxAmount).show();
$(txtSaleTaxAmont).show();
$(lblPoNumber).show();
$(txtPoNumber).show();
$(lblTaxType).show();
$(ddlTaxType).show();
}
});