ここで、要素のjquery条件とともにasp.netコードとグローバル変数を追加しました。このコードはうまく機能しますが、このコードを簡素化したいと思います。誰でもこれについて助けることができますか?
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 %>';
Jクエリコード
$(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();
}
});