简体   繁体   English

切换div以在点击时显示,而切换另一个以隐藏

[英]Toggle a div to show on click while toggling another to hide

Have two divs that represent the same data only one goes into more detail.On the button click, I need to slideToggle the first div and then toggle open or slideDown the second. 有两个表示相同数据的div,只有一个更详细。单击按钮时,我需要slideToggle第一个div,然后切换open或slideDown第二个。 Basically switching out what is shown but it needs to be in two separate divs so it can not be a basic toggle in the same div. 基本上切换显示的内容,但它必须位于两个单独的div中,因此它不能是同一div中的基本切换。 Any ideas please: 任何想法请:

html: EDIT html:编辑

<div id="basicTermsRow">
  <div class="row">
    <div class="col-sm-4">
      <div class="standardList">
        <ul>
          <li>Random Data</li>
          <li>This be the div I need to hide<span class="glyphicon glyphicon-cloud"></span></li>
        </ul>
      </div>
    </div>
 </div>
</div>

<div id="expandedTerms">
<div class="row">
  <div class="col-lg-12">
 <p>Good Bye</p>
 </div>

js: js:

$( "#editButton" ).click(function() {
$( "#basicTermsRow" ).slideToggle( "fast" );
});

Fiddle: 小提琴:

http://jsfiddle.net/ZB8u9/1/ http://jsfiddle.net/ZB8u9/1/

The first thing you need to do is to make the expanded div initially hidden. 您需要做的第一件事是使扩展div最初处于隐藏状态。 Then to achieve what you want you can simply toggle both divs when the user presses the button. 然后,要实现所需的功能,只需在用户按下按钮时切换两个div。 Like this: 像这样:

<div id="expandedTerms" style="display:none">

Though it's preferrable to do the hiding in your CSS to avoid inline styling. 虽然最好在CSS中进行隐藏以避免内联样式。

The script will look like this: 该脚本将如下所示:

$( "#editButton" ).click(function() {
  $( "#basicTermsRow" ).slideToggle( "fast" );
  $( "#expandedTerms" ).slideToggle( "fast" );
});

http://jsfiddle.net/ZB8u9/3/ http://jsfiddle.net/ZB8u9/3/

I think you need to hide one of them first, otherwise it is a bit nonsense. 我认为您需要先隐藏其中之一,否则有点废话。 My suggestion 我的建议

$( "#expandedTerms" ).hide();
$( "#editButton" ).click(function() {
    $( "#basicTermsRow" ).slideToggle();
    $( "#expandedTerms" ).slideToggle();
});

If I understand correctly, considering that these two entries are line items, I would suggest assigning them a class so that you can apply whatever kind of toggle you want to each of them. 如果我理解正确,考虑到这两个条目都是行项目,建议您为它们分配一个类,以便可以将所需的任何切换应用于它们。 See the JSFiddle for an example. 有关示例,请参见JSFiddle

$( "#editButton" ).click(function() {
$( ".hideDiv" ).slideToggle("fast");}
);

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

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