【问题标题】:first toggle div needs to start open第一个切换 div 需要开始打开
【发布时间】:2013-07-03 18:32:48
【问题描述】:

我有 2 个 div 分组(“问题”和“答案”)。
当点击“问题”时,会显示“答案”。
当再次单击“问题”(或单击另一个“问题”)时,当前可见的“答案”会隐藏,而新的会显示。
我不知道如何使该系列的第一个问题/答案集在页面加载时显示

代码:

jQuery(document).ready(function() {
    jQuery(".answer").hide();
    jQuery(".question").click(function() {
        jQuery(".answer").not(jQuery(this).next(".answer")).hide();
        jQuery(this).next(".answer").toggle();
    });
});

演示:http://jsfiddle.net/pixeloco/Y724r/

【问题讨论】:

    标签: html load toggle hide show


    【解决方案1】:

    只需触发点击first-child

    jQuery(document).ready(function () {
    
        jQuery(".answer").hide();
        jQuery(".question").click(function () {
            jQuery(".answer").not(jQuery(this).next(".answer")).hide();
            jQuery(this).next(".answer").toggle();
        });
        jQuery('.question:first-child').trigger('click');
    });
    

    Check the fiddle

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-06-30
      • 2020-07-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-26
      • 1970-01-01
      相关资源
      最近更新 更多