English 中文(简体)
页: 1 Qu 幻灯 暂时搁置一旁,而不是独立
原标题:jQuery slideToggle one div at a time instead of all independently

I m using the function below that toggles divs, and with it, any one of the entry-content divs can be opened or closed independently of all.

What would be great is if only one entry-content div would be open at any time. Clicking a closed entry-title div would close any other entry-content div and then open the one clicked. I need to stay with the html markup, as it is created dynamically by Wordpress. Is this possible?

<>功能:

jQuery(document).ready(function($) {
$(".entry-content").hide( slow );
$(".entry-title").click(function() {
$(this).parent().children(".entry-content").slideToggle(500); });
});

<><><><>>>>>

<div class="entry-post">

   <h2 class="entry-title">Post Title 1</h2>

   <div class="entry-content">Lorem Ipsum...

</div></div>

   <h2 class="entry-title">Post Title 2</h2>

   <div class="entry-content">Lorem Ipsum...

</div></div>

More of the same....

</div>
最佳回答

每次被点击时,就立即结束:

jQuery(document).ready(function($) {
$(".entry-content").hide( slow );
$(".entry-title").click(function() {
    $(".entry-content").hide();
$(this).parent().children(".entry-content").slideToggle(500); });
});

例:

问题回答

是的,你只能使用这一逻辑:

$(".entry-title").click(function() {
    // hide all entry title elements
    $( .entry-title ).hide();
    // show the clicked one
    $(this).show();
});

You can adjust it to use toggle instead of hide/show.

我通常采用这种逻辑,将特殊物品类别分配给要素(使事情更加分离)。 因此,当我点击元件时,我给它增加一个类别。 但是,当你点击另一个因素时,你必须同这一类人员接触,但你只想一个。 因此,你们必须加以修改。 首先将这一类别从所有要素中删除,然后添加到点击元件中。

$(".anyAffectedElement").click(function() {
    // remove any instances of special class
    $( .enabledElement ).removeClass( eneabledElement );
    // add special class to clicked element 
    $(this).addClass( enabledElement );
});

^ 这只是你如何处理类似问题的一般逻辑。 简而言之,这只使Element类别增加了一些特殊杂交(如强调)。

我不理解其他人提出的这些例子,但最后是,如果有人需要一种解决办法,则在另一个地方找到答案:。 http://jsfiddle.net/bipen/zBdFQ/1/

@markratledge——首先,你们需要赠送离家门,而不是课堂。

$("#link1").click(function(e) {
  e.preventDefault();
  $("#div1").slideDown(slow);
  $("#div2").slideUp(slow);
});

$("#link2").click(function(e) {
  e.preventDefault();
  $("#div1").slideUp(slow);
  $("#div2").slideDown(slow);
});




相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签