3

shareThis機能を実装できる次のコードがあります。私がやろうとしているのは、このオーバーレイの共有の閉じるボタンをクリックしたときに、に付属しているshareThis機能を削除してから.share-span再初期化しようとしていますが、DOMremove()から削除されていないようです。.span-share

<script type="text/javascript">
function getShareData() {
    jQuery(".suit-gallery-btn").each(function(index){
        jQuery(this).children().remove('span');
        jQuery(this).append("<span class='share-span'></span>"); // ShareThis button will be inserted in this span, which we are appending to each <div class="suit-gallery-btn">
        var suitLink = jQuery(this).find('a'); // the "click more information" link. you will need the href and title from this element.
        console.log(suitLink);
        stWidget.addEntry({
            "service":"email",
            "element": jQuery(this).find('.share-span')[0],
            "title":suitLink.attr('title'),
            "type":"large",
            "text":suitLink.attr('title'),
            "image": suitLink.attr('href'),
            "summary":suitLink.attr('title'),
            "onhover": false
        });
    });
}

jQuery(document).ready(function() {
    getShareData();
    jQuery("#closeX, #greyScreen, .stCloseNew2, .close, .close2").live("click", function(){
        getShareData();
    });
});

    <div id="suit-gallery">
  <img src="../images/galleries/business/DSC_0055_sm.jpg" alt="Stylish button 3 business suit, beige lightweight high twist cool wool Holland &amp; Sherry" width="164" height="247" />
  <div class="suit-gallery-btn">
    <a href="../images/galleries/business/DSC_0055.jpg" rel="lightbox[business]" title="Stylish button 3 suit, beige lightweight high twist cool wool Holland &amp; Sherry from £695 choice of 90 designs and colours">Click for more information</a>
</div>
</div>
4

3 に答える 3

2

removeのセマンティクスを誤解しました。

削除する親オブジェクトからではなく、削除する必要のあるオブジェクトに対してremoveを呼び出します。

何かのようなもの:

 jQuery('span.share-span', jQuery(this)).remove();
于 2011-08-24T11:58:12.597 に答える
2

この行を変更します。

jQuery(this).children().remove('span');

に:

jQuery(this).children('span.share-span').remove();

http://jsfiddle.net/MarkSchultheiss/CUrXF/で、元のスパンを表示するように少し変更してから、関数が呼び出されたときに削除します。

于 2011-08-24T12:02:43.640 に答える
1

私が見ることができることからspan、元のコードには何もありません。

あなたがそれを手に入れる前にあなたがしようとしremove()ているように見えますか?spanappended

于 2011-08-24T11:59:31.993 に答える