简体   繁体   English

选择下拉菜单后,图片显示/可见

[英]Image in/visible after dropdown choice

When I select a language in the dropdown menu the matching language image should appear in a div next to it, making the irrelevant images invisible. 当我在下拉菜单中选择一种语言时,匹配的语言图像应显示在它旁边的div ,从而使不相关的图像不可见。 I can't get it to work, I've been trying with display: none; 我无法使其正常工作,我一直在尝试使用display: none; and block; block; and with .hide() .show() 并用.hide() .show()

Can someone see what I am doing wrong here? 有人可以在这里看到我做错了吗?

<form id="form1" runat="server">
  <div id="navLanguage">
    <asp:DropDownList ID="ddlLanguages" runat="server" AutoPostBack="True" >
    <asp:ListItem Text="English" Value="en-us" />
    <asp:ListItem Text="Nederlands" Value="nl" />
    <asp:ListItem Text="Português" Value="pt-br" />
    </asp:DropDownList>
  </div>
</form>

<div ID="Flags" runat="server">
    <asp:Image runat="server" ID="FlagUK" imageUrl="Images/Language Icons/FlagUK.png" Value="en-us" />
    <asp:Image runat="server" ID="FlagNL" imageUrl="Images/Language Icons/FlagNL.png" Value="nl" />
    <asp:Image runat="server" ID="FlagBR" imageUrl="Images/Language Icons/FlagBR.png" Value="pt-br" />
</div>

<script src="https://code.jquery.com/jquery-1.3.2.min.js"></script> 
<script type="text/javascript">
  $(document).ready(function () {
    $('#ddlLanguages').on ('change', function () {
      var selected = $(this).val();
      if (selected === "en-us") {
        $('#FlagUK').show();
        $('#FlagNL').hide();
        $('#FlagBR').hide();
      }
      if (selected === "nl") {
        $('#FlagUK').hide();
        $('#FlagNL').show();
        $('#FlagBR').hide();
      }
      if (selected === "pt-br") {
        $('#FlagUK').hide();
        $('#FlagNL').hide();
        $('#FlagBR').show();
      }
    });
 });
</script>

尝试将“更改”事件更改为“单击”事件,以这种方式直接选择dom并从中获取值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM