我试图这样做,当用户选择某个项目时,它会通过将标签的可见属性设置为" true"来为用户提供一些信息,它应该相对简单但是我似乎无法使其发挥作用。我正在使用Web表单。
Aspx代码:
<label for="footerPlaceHolder_twoFactorAuthentication" class="sr-only"><asp:Localize runat="server" Text="<%$ Resources:UserMessages, SelectTwoFactor %>"></asp:Localize></label>
<asp:DropDownList runat="server" ID="twoFactorAuthenticationDropDownList" OnSelectedIndexChange="twoFactorAuthenticationDropDownList_SelectedIndex" CssClass="selectpicker">
<asp:ListItem Value="0" Text = "<%$ Resources:UserMessages, SelectTwoFactor %>"></asp:ListItem>
<asp:ListItem Value="1" Text = "<%$ Resources:UserMessages, RequireTwoFactor %>" ></asp:ListItem>
<asp:ListItem Value="2" Text = "<%$ Resources:UserMessages, RecommendTwoFactor %>" ></asp:ListItem>
<asp:ListItem Value="3" Text = "<%$ Resources:UserMessages, TwoFactorNotRequired %>" ></asp:ListItem>
</asp:DropDownList>
<p><asp:RequiredFieldValidator runat="server" ControlToValidate="paymentDay" CssClass="field-validation-error" ErrorMessage="<%$ Resources:ErrorMessages, ValidationPaymentDayRequired %>" InitialValue="0" EnableClientScript="true" Display="Dynamic"></asp:RequiredFieldValidator></p>
<h3><asp:Localize runat="server" ID="noticeLabel" Visible="false" Text="<%$ Resources:UserMessages, Notice %>"></asp:Localize></h3>
<h5 class="leftspace"><asp:Localize runat="server" ID="noticeText" Visible="false" Text="<%$ Resources:UserMessages, NoticeInfo %>"></asp:Localize></h5>
我尝试过的事情:
$(function(){
if($("#twoFactorAuthenticationDropDownList").val() == 3)
$("#noticeText").visible("true");
});
答案 0 :(得分:0)
试试这个
$(function(){
if($("#twoFactorAuthenticationDropDownList :selected").val() === '3') {
$("#noticeinfo").visible("true");
}
});
答案 1 :(得分:0)
aspx代码:
<label for="footerPlaceHolder_twoFactorAuthentication" class="sr-only"><asp:Localize runat="server" Text="<%$ Resources:UserMessages, TwoFactorSelect %>"></asp:Localize></label>
<asp:DropDownList runat="server" ID="twoFactorAuthenticationDropDownList" CssClass="selectpicker" AppendDataBoundItems="True">
<asp:ListItem Value="0" Text = "<%$ Resources:UserMessages, TwoFactorSelect %>"></asp:ListItem>
<asp:ListItem Value="1" Text = "<%$ Resources:UserMessages, TwoFactorRequire %>" ></asp:ListItem>
<asp:ListItem Value="2" Text = "<%$ Resources:UserMessages, TwoFactorRecommend %>" ></asp:ListItem>
<asp:ListItem Value="3" Text = "<%$ Resources:UserMessages, TwoFactorNotRequired %>" ></asp:ListItem>
</asp:DropDownList>
<p><asp:RequiredFieldValidator runat="server" ControlToValidate="twoFactorAuthenticationDropDownList" CssClass="field-validation-error" InitialValue="3" EnableClientScript="true" Display="Dynamic"></asp:RequiredFieldValidator></p>
<span ID="noticeinfo" class="leftspace"><asp:Localize runat="server" ID="noticeText" Text="<%$ Resources:UserMessages, NoticeInfo %>"></asp:Localize></span>
<asp:HiddenField runat="server" Value="<%$ Resources:UserMessages, twofactorMessage0 %>" ID="twofactorMessage0" />
<asp:HiddenField runat="server" Value="<%$ Resources:UserMessages, twofactorMessage1 %>" ID="twofactorMessage1" />
<asp:HiddenField runat="server" Value="<%$ Resources:UserMessages, twofactorMessage2 %>" ID="twofactorMessage2" />
<asp:HiddenField runat="server" Value="<%$ Resources:UserMessages, twofactorMessage3 %>" ID="twofactorMessage3" />
工作js。代码:
$('#footerPlaceHolder_twoFactorAuthenticationDropDownList').on('change', function (e) {
var selectedValue = $('#footerPlaceHolder_twoFactorAuthenticationDropDownList').val();
console.log("Value of dropdown is: " + selectedValue);
$('#noticeinfo').text($('#footerPlaceHolder_twofactorMessage' + selectedValue).val());