简体   繁体   English

如何使用jQuery Bootstrap在按钮单击上显示特定的div

[英]how to display specific div on button click using jquery bootstrap

I have four buttons in a button group and I want a specific button has to show some specific div content on its click. 我在一个按钮组中有四个按钮,我希望一个特定的按钮在单击时必须显示一些特定的div内容。

The content has to show according to which button is clicked. 内容必须根据单击哪个按钮来显示。

How can I do this using twitter bootstrap jQuery in asp.net? 如何在asp.net中使用Twitter Bootstrap jQuery做到这一点?

Below is a way to do with jQuery 以下是使用jQuery一种方法

$('.btn-group').find('button').click(function () {
    alert($(this).text());
    // here you can check the value and act upon
});

JSFiddle JSFiddle

You can use bootstrap Collapse . 您可以使用bootstrap Collapse According to the documentation: 根据文档:

Just add data-toggle="collapse" and a data-target to element to automatically assign control of a collapsible element. 只需将data-toggle =“ collapse”和一个data-target添加到元素即可自动分配对可折叠元素的控制权。 The data-target attribute accepts a CSS selector to apply the collapse to. data-target属性接受CSS选择器来应用折叠。 Be sure to add the class collapse to the collapsible element. 确保将类折叠添加到可折叠元素中。 If you'd like it to default open, add the additional class in. 如果您希望它默认打开,请在其中添加其他类。

Here is a basic demo. 这是一个基本的演示。 http://www.bootply.com/jIyBm4IaoL . http://www.bootply.com/jIyBm4IaoL

HTML: HTML:

<button type="button" class="btn btn-danger" data-toggle="collapse" data-target="#demo1">
    btn1 
</button>
<button type="button" class="btn btn-danger" data-toggle="collapse" data-target="#demo2">
    btn2
</button>
<button type="button" class="btn btn-danger" data-toggle="collapse" data-target="#demo3">
    btn3
</button>
<button type="button" class="btn btn-danger" data-toggle="collapse" data-target="#demo4">
    btn4
</button>
<div id="demo1" class="collapse">
    ddassdfsdf
</div>
<div id="demo2" class="collapse">
    2343434  
</div>
<div id="demo3" class="collapse">
    465656 vbgtrsdf
</div>
<div id="demo4" class="collapse">
    4545bn c sasdasdfasd
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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