Wordpress Gallery:使用jquery删除<br/>标签

时间:2012-03-15 19:33:12

标签: jquery wordpress tags

我正在尝试通过jquery从wordpress本地库中删除<br />标记,并尝试了很多方法,但没有一种方法有效..

我在下面尝试过几个代码(注意:我已将主题文件<br style="clear:both" />更改为<br class="clearboth" />我也已取消注册jquery并使用googleapis注册我的主题。

<script>$('br.clearboth').html();</script>

<script>
(function($) {
    $.strRemove = function(theTarget, theString) {
        return $("<br/>").append(
            $(theTarget, theString).remove().end()
        ).html();
    };
})(jQuery);
</script>

我将此代码正好放在wordpress的入口div的顶部。可能是我把脚本放在错误的地方。没有任何工作,也没有从画廊部分删除任何br标签......

我得到的实际源代码如下所示..我已经尝试了js,因为你的家伙说但不知道你在源代码中可以看到 仍在那里。

<!--BEGIN: Single Post-->
    <article class="post-866 gallery type-gallery status-publish hentry mp_gallery" id="post-866">

        <div class="entry">

        <!--[this js i have added here]-->
        <script>
            $("br.clearboth").remove();
        </script>


            <style type='text/css'>
                #gallery-1 {
                    margin: auto;
                }
                #gallery-1 .gallery-item {
                    float: left;
                    margin-top: 10px;
                    text-align: center;
                    width: 33%;
                }
                #gallery-1 img {
                    border: 2px solid #cfcfcf;
                }
                #gallery-1 .gallery-caption {
                    margin-left: 0;
                }
            </style>
            <!-- see gallery_shortcode() in wp-includes/media.php -->
        <ul id='gallery-1' class='gallery galleryid-866 gallery-columns-3 gallery-size-thumbnail clearfix'><li class='gallery-item'>
                <p class='gallery-icon'>
                    <a href='http://localhost/mediatuts/wp-content/uploads/2012/03/DSC_0432.jpg' title='DSC_0432'><img width="190" height="110" src="http://localhost/mediatuts/wp-content/uploads/2012/03/DSC_0432-190x110.jpg" class="attachment-thumbnail colorbox-866" alt="Lorem ipsum dolor sit amet," title="DSC_0432" /></a>
                </p>
                    <p class='wp-caption-text gallery-caption'>

                    Lorem ipsum dolor sit amet, 
                    </p></li><li class='gallery-item'>
                <p class='gallery-icon'>
                    <a href='http://localhost/mediatuts/wp-content/uploads/2012/03/DSC_0503.jpg' title='DSC_0503'><img width="190" height="110" src="http://localhost/mediatuts/wp-content/uploads/2012/03/DSC_0503-190x110.jpg" class="attachment-thumbnail colorbox-866" alt="Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium" title="DSC_0503" /></a>
                </p>
                    <p class='wp-caption-text gallery-caption'>
                    Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium
                    </p></li><li class='gallery-item'>
                <p class='gallery-icon'>
                    <a href='http://localhost/mediatuts/wp-content/uploads/2012/03/DSC_0516.jpg' title='DSC_0516'><img width="190" height="110" src="http://localhost/mediatuts/wp-content/uploads/2012/03/DSC_0516-190x110.jpg" class="attachment-thumbnail colorbox-866" alt="DSC_0516" title="DSC_0516" /></a>

                </p></li>

                <br class="clearboth" />

                <li class='gallery-item'>
                <p class='gallery-icon'>
                    <a href='http://localhost/mediatuts/wp-content/uploads/2012/03/DSC_0657.jpg' title='DSC_0657'><img width="190" height="110" src="http://localhost/mediatuts/wp-content/uploads/2012/03/DSC_0657-190x110.jpg" class="attachment-thumbnail colorbox-866" alt="Most beautiful face evern catched before" title="DSC_0657" /></a>
                </p>
                    <p class='wp-caption-text gallery-caption'>
                    Most beautiful face evern catched before
                    </p></li><li class='gallery-item'>
                <p class='gallery-icon'>
                    <a href='http://localhost/mediatuts/wp-content/uploads/2012/03/DSC_0658.jpg' title='DSC_0658'><img width="190" height="110" src="http://localhost/mediatuts/wp-content/uploads/2012/03/DSC_0658-190x110.jpg" class="attachment-thumbnail colorbox-866" alt="Beauty queen on the earth and praising pain was born and But I must explain to you how all this" title="DSC_0658" /></a>

                </p>
                    <p class='wp-caption-text gallery-caption'>
                    Beauty queen on the earth and praising pain was born and But I must explain to you how all this
                    </p></li><li class='gallery-item'>
                <p class='gallery-icon'>
                    <a href='http://localhost/mediatuts/wp-content/uploads/2012/03/DSC_0676.jpg' title='DSC_0676'><img width="190" height="110" src="http://localhost/mediatuts/wp-content/uploads/2012/03/DSC_0676-190x110.jpg" class="attachment-thumbnail colorbox-866" alt="Handsome Guy will Look after you :)" title="DSC_0676" /></a>
                </p>
                    <p class='wp-caption-text gallery-caption'>
                    Handsome Guy will Look after you :)
                    </p></li>

                    <br class="clearboth" />

                    <li class='gallery-item'>

                <p class='gallery-icon'>
                    <a href='http://localhost/mediatuts/wp-content/uploads/2012/03/DSC_0677.jpg' title='DSC_0677'><img width="190" height="110" src="http://localhost/mediatuts/wp-content/uploads/2012/03/DSC_0677-190x110.jpg" class="attachment-thumbnail colorbox-866" alt="Dashing Guy who is looking for a gal" title="DSC_0677" /></a>
                </p>
                    <p class='wp-caption-text gallery-caption'>
                    Dashing Guy who is looking for a gal
                    </p></li><li class='gallery-item'>
                <p class='gallery-icon'>
                    <a href='http://localhost/mediatuts/wp-content/uploads/2012/03/DSC_0125.jpg' title='DSC_0125'><img width="190" height="110" src="http://localhost/mediatuts/wp-content/uploads/2012/03/DSC_0125-190x110.jpg" class="attachment-thumbnail colorbox-866" alt="DSC_0125" title="DSC_0125" /></a>
                </p></li><li class='gallery-item'>

                <p class='gallery-icon'>
                    <a href='http://localhost/mediatuts/wp-content/uploads/2012/03/DSC_0416.jpg' title='DSC_0416'><img width="190" height="110" src="http://localhost/mediatuts/wp-content/uploads/2012/03/DSC_0416-190x110.jpg" class="attachment-thumbnail colorbox-866" alt="One morning, when Gregor Samsa woke from troubled dreams, he found himself transformed in his bed into a horrible vermin." title="DSC_0416" /></a>
                </p>
                    <p class='wp-caption-text gallery-caption'>
                    One morning, when Gregor Samsa woke from troubled dreams, he found himself transformed in his bed into a horrible vermin. 
                    </p></li>

                    <br class="clearboth" />

                    <li class='gallery-item'>
                <p class='gallery-icon'>
                    <a href='http://localhost/mediatuts/wp-content/uploads/2012/03/DSC_0431.jpg' title='DSC_0431'><img width="190" height="110" src="http://localhost/mediatuts/wp-content/uploads/2012/03/DSC_0431-190x110.jpg" class="attachment-thumbnail colorbox-866" alt="DSC_0431" title="DSC_0431" /></a>
                </p></li>

                <br style='clear: both;' />
            </ul>

    </article>

    <!--END: Single Post-->

2 个答案:

答案 0 :(得分:3)

如果您尝试从DOM中删除br标记,则可以执行以下操作:

$("br").remove();

如果您只想要特定的课程,请执行以下操作:

$("br.clearboth").remove();

如果您只想从特定节点中删除br标签,请执行以下操作:

$("#someId br.clearboth").remove();

答案 1 :(得分:3)

您的代码目前的功能还不是很清楚,但您可以从DOM中删除br元素,如下所示:

$('br').remove();

您可以在特定容器中定位br元素,如下所示:

$('#container-id').find('br').remove();

以下是演示:http://jsfiddle.net/YtedC/