JS this 的使用 隐藏显示某段DIV

来源:互联网 发布:centos查看gcc 编辑:程序博客网 时间:2024/05/27 09:48

利用JS隐藏显示某段DIV

                            <div class="tcbm_text">
                                <span class="reply" onclick="showCommen()" >{{:commentCount}}</span>
                            </div>
                            <div class="tcbm_rebox" >
                </div>


            //显示隐藏切换 tcbm_rebox
            function showCommen(){
                $(this).parent().next().toggle();
            };
            
    错误,$(this)并不能定位到具体的span
    原因:JS并不能判断 this 具体是哪一个元素
    修改方法一:
                            <div class="tcbm_text">
                                <span class="reply" onclick="showCommen(this)" >{{:commentCount}}</span>
                            </div>
                            <div class="tcbm_rebox" >
                </div>


            //显示隐藏切换 tcbm_rebox
            function showCommen(tar){
                $(tar).parent().next().toggle();
            };

    修改方法二:
                            <div class="tcbm_text">
                                <span class="reply" onclick="showCommen()" >{{:commentCount}}</span>
                            </div>
                            <div class="tcbm_rebox" >
                </div>


            //显示隐藏切换 tcbm_rebox
            $("span.replay").click(function(){
        $(this).parent().next().toggle();
        });

0 0