jquery - css jquery隐藏一个div,显示另一个

标签 jquery css hide show

我遇到了挑战。 我有 2 个 div,其中一个在页面加载时在 css 中设置为 display:none; 我有两个对应的链接。当用户单击 link1 时,我想显示 div1 并隐藏 div2。当用户单击 link2 时,我想显示 div2 并隐藏 div1

我还没能让它发挥作用!非常感谢任何帮助。

最佳答案

这里是一个例子:

$(function () {
  $(".div1, .div2").hide();

  $(".link1, .link2").bind("click", function () {
    $(".div1, .div2").hide();        

    if ($(this).attr("class") == "link1")
    {
      $(".div1").show();
    }
    else
    {
      $(".div2").show();
    }
  });

});

这是Demo

关于jquery - css jquery隐藏一个div,显示另一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11761049/

相关文章:

jquery - css div 背景变得更左

jquery - 使用 CSS 或 Jquery 将两个 block 定位在桌面的绝对位置和移动设备的相对位置

jquery - 当 child 是一个类(class)时,如何访问 $(this) 选择器的 child ?

jQuery 更改文件夹与 css 更改

javascript - 使用 RequireJS 模块化 CSS 样式表

jQuery 验证 : Show/hide custom elements besides the default elements

javascript - 如何获取输入文件值而不是使用 FormData

javascript - 通过 src 删除图像

javascript - jquery 函数 '.on("click")' starts uncalled

javascript - 如何在点击时使用 FB Like 按钮 Conceal iframe?