0

私はこのようなHTMLをいくつか持っています。

<div class="suit-gallery">
  <img src="../images/galleries/business/DSC_0035_sm.jpg" alt="Stylish button 2 business suit with contrast buttonholes light weight high twist cool wool" width="164" height="247" />
  <div class="suit-gallery-btn">
    <a href="../images/galleries/business/DSC_0035.jpg" rel="lightbox[business]" title="Stylish button 2 suit with contrast buttonholes light weight high twist cool wool Holland &amp; Sherry from £695, choice of 90 designs/colours">Click for more information</a>
</div>
</div>

<div class="suit-gallery">
  <img src="../images/galleries/business/DSC_0010_sm.jpg" alt="Classic button 2 business suit with an out ticket pocket. Grey wool Holland &amp; Sherry Perennial" width="164" height="247" />
  <div class="suit-gallery-btn">
    <a href="../images/galleries/business/DSC_0010.jpg" rel="lightbox[business]" title="Classic button 2 suit with an out ticket pocket. Grey wool Holland &amp; Sherry Perennial from £895, choice of 120 designs/colours" >Click for more information</a>
</div>
</div>

<div class="clear">&nbsp;</div>

<div class="suit-gallery">
  <img src="../images/galleries/business/DSC_0024_sm.jpg" alt="Modern 2 button business suit grey 100% Yorkshire worsted" width="164" height="247" />
  <div class="suit-gallery-btn">
    <a href="../images/galleries/business/DSC_0024.jpg" rel="lightbox[business]" title="Modern 2 button suit 100% Yorkshire worsted from £795 choice of 85 designs/colours" >Click for more information</a>
</div>

の各インスタンスに sharethis メール リンクを追加したいのですが.suit-gallery-btn、これを行う方法がわかりません。また、リンクのリンクのタイトルをキャプション オプションに追加し、画像 URL を画像オプションに追加したいと考えています。私が現在持っているもの、

jQuery(document).ready(function(){
    stWidget.addEntry({
    "service":"email",
    "element": document.getElementById('button_1'),
    "url":"http://sharethis.com",
    "title":"What do you think to this suit?",
    "type":"large",
    "text":"What do you think to this suit?" ,
    "image": "",
    "summary":""
    });
});

また、id ではなくクラスに基づいて要素を選択する必要があることも知っています。要素がいくつあっても、これを行う必要が.suit-gallery-btnあります。

私は完全に迷っています。

4

1 に答える 1

1

次のようなことを試してください:

$(".suit-gallery-btn").each(function(){

    $(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 = $(this).find('a'); // the "click more information" link. you will need the href and title from this element.

    stWidget.addEntry({
        "service":"email",
        "element": $(this).find('.share-span')[0],
        "url":suitLink.attr('href'),
        "title":suitLink.attr('title'),
        "type":"large",
        "text":suitLink.attr('title'),
        "image": suitLink.attr('href'),
        "summary":suitLink.attr('title')
    });


});

デモ用の JS フィドルを次に示します: http://jsfiddle.net/RR26b/

(無効な画像参照によるエラーや、ShareThis Publisher キーの欠如によるエラーがありますが、コンセプトは機能するはずです)

于 2011-08-23T20:35:20.533 に答える