Javascript sharethis和jquery帮助

Javascript sharethis和jquery帮助,javascript,social-media,sharethis,jquery,Javascript,Social Media,Sharethis,Jquery,我有一些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 cla

我有一些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>
我还知道,我必须根据类而不是id来选择元素,无论有多少
。suit gallery btn
,我都需要这样做


我完全迷路了。

试试这样的方法:

$(".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')
    });


});
$(“.suit gallery btn”)。每个(函数(){
$(this).append(“”;//ShareThis按钮将插入到这个跨度中,我们将每个跨度都附加到这个跨度中
var suitelink=$(this).find('a');//单击“更多信息”链接。您需要此元素的href和标题。
stWidget.addEntry({
“服务”:“电子邮件”,
“元素”:$(this.find('.share span')[0],
“url”:suitelink.attr('href'),
“title”:suitelink.attr(“title”),
“类型”:“大型”,
“文本”:suitelink.attr('title'),
“image”:suitelink.attr('href'),
“摘要”:suitelink.attr(“标题”)
});
});
下面是一个JS小提琴来演示:


(由于无效的图像引用和缺少ShareThis发布者密钥,会出现错误,但这个概念应该有效)

非常感谢,我如何停止ShareThis小部件,让每个按钮显示相同的信息?如果我在我的一个链接上触发小部件,那么该数据将用于所有sharethis按钮
$(".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')
    });


});