【问题标题】:sharethis and jquery helpsharethis 和 jquery 帮助
【发布时间】:2011-11-02 02:53:45
【问题描述】:

我有一些看起来像这样的 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>

我想为.suit-gallery-btn 的每个实例添加一个sharethis 邮件链接,但是我不知道如何做到这一点,我还想将链接链接的标题添加到标题选项中,并将图像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 有多少,我都需要这样做。

我完全迷路了。

【问题讨论】:

    标签: javascript social-media sharethis jquery


    【解决方案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 fiddle 来演示:http://jsfiddle.net/RR26b/

    (由于无效的图像引用以及缺少 ShareThis Publisher Key 导致错误,但该概念应该有效)

    【讨论】:

    • 非常感谢,我怎样才能停止 sharethis 小部件只为每个按钮显示相同的信息?如果我在其中一个链接上触发小部件,则该数据将用于所有 sharethis 按钮
    猜你喜欢
    • 1970-01-01
    • 2011-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多