【问题标题】:Hide an element inside an element with a class将元素隐藏在具有类的元素中
【发布时间】:2016-08-29 12:18:39
【问题描述】:

我想将<p class="crfp-field"> 隐藏在<ol class="comment-list"> 中,如果它不在其中,则显示它。希望你能帮我解决这个问题。这是代码的样子

<ol class="comment-list">
    <li class="comment">
        <div id="comment-n">
            <p>This is a comment</p>
        </div>

        <ul class="children">
            <li class="comment">
                <div id="comment-n">
                    <p>This is a reply to a comment. Star rating is visible here. I don’t want to display it when I am replying to a comment.</p>
                </div>
                <div id="respond" class="comment-respond">
                    <h3 id="reply-title" class="comment-reply-title">Write a Reply or Comment <small><a class="btn" rel="nofollow" id="cancel-comment-reply-link" href="" style="">Cancel Reply</a></small></h3>
                    <form action="http://../wp-comments-post.php" method="post" id="commentform" class="comment-form">
                        <p class="comment-notes">Your email address will not be published.</p>
                        <p class="comment-form-author">Name<input id="author" name="author" type="text"></p>
                        <p class="comment-form-email">Email<input id="email" name="email" type="text"></p>
                        <p class="comment-form-url">Website<input id="url" name="url" type="text"></p>
                        <!-- CRFP Fields: Start -->
                        <p class="crfp-field">
                            <!-- CRFP Stuff -->
                        </p>
                        <!-- CRFP Fields: End -->
                        <p class="comment-form-comment">Comment<textarea id="comment" name="comment"></textarea></p>
                        <input id="submit-new" value="Post Comment" type="submit">
                    </form>
                </div>
            </li><!-- #comment-## -->
        </ul><!-- .children -->
    </li><!-- #comment-## -->
</ol>

【问题讨论】:

    标签: javascript jquery comments reply


    【解决方案1】:

    应该这样做:

    $('.comment-list .crfp-field').hide();
    

    【讨论】:

    • 它不工作。我把它放在了
    【解决方案2】:

    你可以使用 CSS,不需要 JS:

    ol.comment-list p.crfp-field {
        display: none;
    }
    

    如果p.crfp-field 元素不在ol 内,则不会应用上述规则,该元素将正常显示。

    【讨论】:

    • 没问题,很乐意提供帮助。
    • 干杯!你是救生员:)
    【解决方案3】:

    您可以通过以下方式实现它:

    $(document).ready(function(){
        $("p.crfp-field").show(); //show all p tag with class crfp-field
        $("ol.comment-list p.crfp-field").hide(); //hide the needed ones
    });
    

    【讨论】:

    • 它不工作。也许它与插件的脚本有冲突。安斯,谢谢! CSS 技巧做到了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-01
    • 1970-01-01
    相关资源
    最近更新 更多