我想在 Twitter Bootstrap 模式上显示 share-this 小部件,但是代码显示要执行以下操作:
<span class='st_facebook_hcount' displayText='Facebook'></span>
<span class='st_twitter_hcount' displayText='Tweet'></span>
<span class='st_plusone_hcount' displayText='Google +1'></span>
<span class='st_email_hcount' displayText='Email'></span>
所以我所做的是在 bootstrap 的 shown.bs.modal 事件中我有:
var switchTo5x=true;
$.getScript("http://w.sharethis.com/button/buttons.js", function(){
stLight.options({publisher: "c68c8f6c-c670-419b-b8e2-23772e22a861", doNotHash: false, doNotCopy: false, hashAddressBar: false, popup: 'true'});
});
但是,下次我打开不同的模式时,此共享按钮不会加载。我认为这是因为 getScript 已经存在了?
最佳答案
打开新模态后尝试此操作:
stButtons.locateElements();
它将查找新按钮并实例化它们。
编辑:Listen to the show.bs.modal
event to handle it :
$('#myModal').on('show.bs.modal', function () {
stButtons.locateElements();
})
编辑2: 好吧,读完你的评论后,我认为最终的解决方案是:
var switchTo5x=true;
$.getScript("http://w.sharethis.com/button/buttons.js", function(){
stLight.options({publisher: "c68c8f6c-c670-419b-b8e2-23772e22a861", doNotHash: false, doNotCopy: false, hashAddressBar: false, popup: 'true'});
stButtons.locateElements();
});
关于javascript - 在 Twitter 上分享这个 Bootstrap 模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20396739/