展开/折叠div [英] Expanding / Collapsing divs
问题描述
我在由PHP/MySQL生成的单个页面上有多个展开/折叠框.
I have multiple expanding / collapsing boxes on a single page being generated by PHP / MySQL.
问题是,当我单击一个链接以展开一个框时,它会展开所有框.
Problem is, when I click on one link to expand a box, it expands all the boxes.
我考虑过将帖子ID附加在类(<div class="postreplycontainer-POST_ID">
)的末尾,但我不确定是否可行,因为我必须找出一种更改jQuery的方法.
I thought about appending the post ID at the end of the class (<div class="postreplycontainer-POST_ID">
) but I am not sure if that will work since I'd have to figure out a way to change the jQuery.
这是一个工作示例: http://jsfiddle.net/Draven/kUhkP/35/
请记住,我无法在每个框中手动编写代码,因为我是从数据库中提取内容的.
Keep in mind, I can't manually code in each box because I am pulling the content from the database.
编辑:也许有人可以帮助我解决其他问题.
Maybe somebody can help me with an additional problem.
当我展开<div>
时,我想聚焦textarea
框.我尝试使用与以前相同的技巧(使用.closest
,但这没用).
I want to focus the textarea
box when I expand the <div>
. I tried using the same trick as before (using .closest
but that didn't work).
这里是示例: http://jsfiddle.net/Draven/kUhkP/53/
此示例将始终关注第一个<textarea>
.
This example will always focus the first <textarea>
.
推荐答案
这是 FIDDLE
Here's the FIDDLE
$("a.postreply").click(function () {
$(this).closest('.blog-container')
.find('.postreplycontainer').slideToggle("fast");
});
这篇关于展开/折叠div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!