2014-01-24 71 views
0

我有一個jQuery插件,我已經從代碼峽谷購買社交共享。jquery插件使它綁定onclick

我已將它配置爲單項共享,但是我希望將它連接到頁面上的多個實例。

<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連接到包含函數帶參數的鏈接,以便任何幫助非常感謝

+0

你用的是什麼版本的jquery? 'bind'已被棄用 –

回答

0

嘗試寫你的代碼document.ready()和使用的​​代替bind()還使用data() for data attributes like,

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