简体   繁体   中英

Bootstrap collapse

I've spent a few hours trying to get this bootstrap collapse plugin to work. I'm sorry if this question has been asked a bunch before but I've scoured this place for a suitable answer. Here is my html:

<html lang="en">
 <head>
   <meta charset="utf-8">
   <title>:(</title>
   <!-- Bootstrap -->
   <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
 </head>

 <body>
   <h1>Collapse!</h1>

  <a class="btn btn-danger" data-toggle="collapse" data-target="#demo">
     simple collapsible
  </a>

  <div id="demo" class="collapse in">
        <p>Hopefully this content will be collapsible!</p>
        <p>And this too!</p>
  </div>


<script type="text/javascript">
$(document).ready(function(){
        $(".collapse").collapse()
});
</script>

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="bootstrap/js/bootstrap.min.js"></script>

  </body>
</html>

This is also my first use of stackoverflow to ask a question, so excuse the fact that I don't know how to properly format my question. I just added in that little snippet of jquery in the hopes that it would somehow initialize the js elements on the page. Please help!

这是您的代码的工作版本http://jsbin.com/aximay/1/edit

I see that this question is a bit old, but just an additional note.

It seems there is no need to use the Bootstrap data attributes AND the javascript. The BS docs (see Usage) are not clear that these are distinct alternatives, but it works fine with either one independently (data attributes OR JS).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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