【问题标题】:Jquery plugin make it bind onclickjQuery插件使其绑定onclick
【发布时间】:2014-01-24 04:23:57
【问题描述】:

我有一个 jquery 插件,我是从代码峡谷购买的,用于社交分享。

我已将其配置为单个项目共享,但我希望将其连接到页面上的多个实例。

<script>
$('a.shareplus').shareplus({
    icons: "facebook,twitter,google",
    height : '150px',
    width : '150px',
    shareurl : '#application.settings.websiteurl#/article/' + $(this).attr('data-href'),
    displayTitle : true,
    title : 'Share this item from',
    sticker : false,
    pin : false,
    gplus : false,
    tweets : false,
    fbLikebox : false
});
</script>

这非常适用于网页上共享的单个项目。我已经搜索了这个插件的文档,但是我找不到任何将它附加到单个页面上的多个项目的参考。

我想知道的是..我正在考虑使用 .bind() 方法在单击时连接到它,并使用 data-href 自定义属性来定义要连接到的页面。

但这似乎不起作用。

<script>
$('a.shareplus').bind('click',shareplus({
    icons: "facebook,twitter,google",
    height : '150px',
    width : '150px',
    shareurl : '#application.settings.websiteurl#/article/' + $(this).attr('data-href'),
    displayTitle : true,
    title : 'Share this item from',
    sticker : false,
    pin : false,
    gplus : false,
    tweets : false,
    fbLikebox : false
});


})</script>

我不太确定如何将绑定 api 连接到包含具有参数的函数的链接,因此非常感谢任何帮助

【问题讨论】:

  • 您使用的是什么版本的 jquery? bind 已弃用

标签: javascript jquery plugins


【解决方案1】:

尝试在document.ready() 中编写您的代码并使用on() 而不是bind() 也使用data()data attributes 之类的,

$(function(){
    $('a.shareplus').on('click',function(){
        $(this).shareplus({
            icons: "facebook,twitter,google",
            height : '150px',
            width : '150px',
            shareurl : '#application.settings.websiteurl#/article/'+$(this).data('href'),
            displayTitle : true,
            title : 'Share this item from',
            sticker : false,
            pin : false,
            gplus : false,
            tweets : false,
            fbLikebox : false
        });
    });
});

【讨论】:

    猜你喜欢
    • 2011-04-08
    • 2012-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-20
    • 2012-04-14
    相关资源
    最近更新 更多