首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >sharethis和jquery帮助

sharethis和jquery帮助
EN

Stack Overflow用户
提问于 2011-08-24 00:25:58
回答 1查看 1.2K关注 0票数 0

我有一些看起来像这样的HTML,

代码语言:javascript
复制
<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,但我不知道如何做到这一点,我也想一个标题的链接到标题的链接到标题选项,也到图像网址到图像选项,下面是我目前有,

代码语言:javascript
复制
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,我都需要这样做。

我完全迷路了。

EN

回答 1

Stack Overflow用户

发布于 2011-08-24 04:35:21

尝试如下所示:

代码语言:javascript
复制
$(".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发布者密钥的错误,但概念应该是可行的)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7164317

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档