Jquery隐藏/显示混乱

时间:2012-09-08 16:42:04

标签: jquery

嘿大家我再次遇到脚本问题。我正在为帖子中的成员个人资料数据做jQuery show / hide。请访问http://www.pimpkings.com/t3-what-up-everyone查看我正在谈论的内容,我将代码保留下来,以便您可以了解它正在做什么。

每次点击一个人显示/隐藏它都打开每个人,我只希望它在用户请求时打开1个人。

代码是 -

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".slidingDiv").hide();
 $(".show_hide").show();
    $('.show_hide').click(function(){

$(".slidingDiv").slideToggle();

});

});
</script>

然后html编码

<span class="show_hide" style="cursor:pointer;color:#c0c0c0;">Show/hide</span>
<div class="slidingDiv">
                              <!-- BEGIN profile_field -->
                            <center>    {postrow.displayed.profile_field.LABEL} <center/>
                            <center>  {postrow.displayed.profile_field.CONTENT} <center/>
                            <center>  {postrow.displayed.profile_field.SEPARATOR}<center/>
                            <!-- END profile_field -->
                            <center>{postrow.displayed.profile_field.LABEL}<center/>
                            <center>Online Status<center/><br/>
                            <center>{postrow.displayed.ONLINE_IMG}<center/>
                                        {postrow.displayed.POSTER_RPG} <br />

                            <!-- BEGIN contact_field -->
                             <br/> <br/>
                            {postrow.displayed.PROFILE_IMG} {postrow.displayed.PM_IMG}  
                            {postrow.displayed.EMAIL_IMG} {postrow.displayed.contact_field.CONTENT}
                            <!-- END contact_field -->
                              <span class="show_hide" style="cursor:pointer;color:#c0c0c0;">hide</span></div>
                            </span>

任何人都可以帮忙找出另一个选择器,这样它就不能一次打开吗?

1 个答案:

答案 0 :(得分:0)

试试这个:

$(document).ready(function() {
    $(".slidingDiv").hide();
    $(".show_hide").show();
    $('.show_hide').click(function() {
        $(this).next(".slidingDiv").slideToggle();
    });
});​

请注意,您可能应该将配置文件末尾的“隐藏”链接的类更改为其他内容(例如隐藏),以便您可以使用jQuery更轻松地将其定位以隐藏配置文件。

哦,还有一件事,<center>标签很久以前就被弃用了。使用CSS代替居中。

<强> jsFiddle example

相关问题