javascript - Bootstrap 中的折叠元素

标签 javascript jquery css twitter-bootstrap

<div >
 <div>
  <h3 style="display:inline-block;">Comments</h3>
  <button id="add_button" style="display:inline-block;margin-left:240px;" type="button" class="btn btn-primary" onClick="$('#add_button').hide()" data-toggle="collapse" data-target="#comments">Add</button>
 </div>
 <div id="comments" class="collapse in">
  <textarea style="resize:none;width:90%;" class="input xlarge" rows="4" id="comment-box" name="comment-box" placeholder="Type your comment here..."></textarea>
  <button style="margin-right:30px;" id="submit_comment" class="btn btn-primary pull-right" name="submit_comment" type="submit" onClick="">Submit</button>
 </div>
</div>

所以这是我的代码。我有一个来自 bootstrap 的可折叠元素,我试图让它在页面中开始折叠,但尝试了多种不同的方法我不能。我使用了几个 jQuery 命令,例如 hide() 和 collapse,但它们似乎都不起作用。关于如何让它发挥作用的任何想法?

最佳答案

如我在此 JSFiddle 中所示,只需从 id='comments' div 中删除 in 类,就可以在单击 添加按钮:

http://jsfiddle.net/JHkHE/1/

关于javascript - Bootstrap 中的折叠元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16097387/

相关文章:

javascript - 通过单击关闭谷歌地图上的标记

javascript - jquery 选择的选择验证消息在表单提交之前不会消失

javascript - 评估 html 正文中的 javascript 文本

jquery - 涉及 Rad Editor 和 jQuery .animate 的 CSS 溢出副作用

javascript - 点击显示不同的内容

javascript - 在JS中更改警告框的标题

javascript - 使用 jQuery 获取输入值并在发布之前将其添加到表单操作中

javascript - JQuery表单提交未提交

jquery - Z-index 不适用于 datetimepicker django 小部件

javascript - 使用 jqueryeach(),确保这个 html 表中的列数不超过 5 的最佳方法是什么?