すべての sharethis スパンの属性「st_url」を、jQuery でクリックされたビデオの URL に動的に更新しています。firebug では、スパンの st_url 属性が更新されていることがわかりますが、sharethis ボタンはまだ初期 URL に関連付けられています。要素を再初期化する必要があるかもしれないと読みましたが、これを行う最善の方法がわかりませんか? 誰かがこれを行ったことがありますか、または更新された URL でボタンを再初期化する最良の方法を考えていますか? ありがとう!
Sharethis インクルードと初期化:
<script type="text/javascript">
var switchTo5x=true;
</script>
<script type="text/javascript" src="http://w.sharethis.com/button/buttons.js"></script>
<script type="text/javascript">
stLight.options({publisher:'xxxx'});
</script>
私のマークアップ:
<span st_url="http://sharethis.com" class='st_stumbleupon' ></span>
<span st_url="example" class='st_facebook' ></span>
<span st_url="example" class='st_twitter' ></span>
<span st_url="example" class='st_email' ></span>
ユーザーがビデオをクリックしたときに attr="st_url" を更新する私のjQuery:
//note: this is triggered by .bind('click')
var youtubeID = $(this).attr('id');
$('#container div > span').each(function(){
//update sharethis to current video
$(this).attr('st_url','http://www.youtube.com/watch?v=' + youtubeID);
});