首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用jQuery创建手风琴?

如何使用jQuery创建手风琴?
EN

Stack Overflow用户
提问于 2018-11-25 11:45:03
回答 1查看 290关注 0票数 0

我试图创建一个手风琴,默认情况下,其中一个步骤是默认打开的,其余步骤可以通过单击一个编辑按钮来打开。结构定义如下。

代码语言:javascript
复制
Step 1

Hello world. Lorem ipsum.
--------------------------------------------
Step 2                                  Edit
--------------------------------------------
Step 3                                  Edit
--------------------------------------------
Step 4                                  Edit

现在,如您所见,默认情况下,步骤1的内容是可见的。因此,如果我单击步骤2的“编辑”按钮,步骤1应该折叠,步骤2的内容应该是可见的。

这就是我到目前为止得出的结论。

HTML:

代码语言:javascript
复制
<h6 class="ml-3 mt-3 step-1"><a id="step-one" href="#">Step 1</a></h6>
<br style="clear:both;">
<div id="promo-code" class="mt-5 ml-3">
<p>Abc content</p>
<button type="button" class="btn btn-primary">Continue</button>
</div>

<hr class="ml-3">

<div class="mt-5 ml-3" id="promo-box">
<h6>Step 2</h6>
<p>Abc content</p>
<button type="button" class="btn btn-primary">Continue</button>
</div>

联署材料:

代码语言:javascript
复制
$("#promo-code").click(function(){
document.getElementById("promo-code").style.display = "none";
document.getElementById("promo-box").style.display = "block";
});

$("#step-one").click(function(){
document.getElementById("promo-code").style.display = "block";
document.getElementById("promo-box").style.display = "none";
});

CSS:

代码语言:javascript
复制
#promo-code {
font-size: 15px;
color: #02b875;
}

#promo-box {
display: none;
}

.step-1 {
margin-bottom: -30px;
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-11-25 12:16:42

由于您使用的是引导,下面是引导示例。运行此代码段,功能几乎与您想要实现的功能相同,可以根据需要进行修改。

代码语言:javascript
复制
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/js/bootstrap.min.js"></script>

<div class="accordion" id="accordionExample">
  <div class="card">
    <div class="card-header" id="headingOne">
      <h5 class="mb-0"> Step 1
        <button class="btn btn-link float-right" type="button" data-toggle="collapse" data-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">Edit</button>
      </h5>
    </div>

    <div id="collapseOne" class="collapse show" aria-labelledby="headingOne" data-parent="#accordionExample">
      <div class="card-body">
        Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
      </div>
    </div>
  </div>
  <div class="card">
    <div class="card-header" id="headingTwo">
      <h5 class="mb-0"> Step 2
        <button class="btn btn-link collapsed float-right" type="button" data-toggle="collapse" data-target="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">Edit</button>
      </h5>
    </div>
    <div id="collapseTwo" class="collapse" aria-labelledby="headingTwo" data-parent="#accordionExample">
      <div class="card-body">
        Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
      </div>
    </div>
  </div>
  <div class="card">
    <div class="card-header" id="headingThree">
      <h5 class="mb-0">Step 3
        <button class="btn btn-link collapsed float-right" type="button" data-toggle="collapse" data-target="#collapseThree" aria-expanded="false" aria-controls="collapseThree">
          Edit
        </button>
      </h5>
    </div>
    <div id="collapseThree" class="collapse" aria-labelledby="headingThree" data-parent="#accordionExample">
      <div class="card-body">
        Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
      </div>
    </div>
  </div>
</div>

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53467094

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档