打开多说embed.js,可以找到下列代码

      O = S.selectors = {
            ".ds-thread": {
                type: "EmbedThread"
            },
            ".ds-recent-comments": {
                type: "RecentComments"
            },
            ".ds-recent-visitors": {
                type: "RecentVisitors"
            },
            ".ds-top-users": {
                type: "TopUsers"
            },
            ".ds-top-threads": {
                type: "TopThreads"
            },
            ".ds-login": {
                type: "LoginWidget"
            },
            ".ds-thread-count": {
                type: "ThreadCount"
            },
            ".ds-share": {
                type: "ShareWidget"
            }
        },

多说也够良心,给了这么多可以回调的函数,方便我们使用~

比如,回调评论框:

if ($('.ds-thread').length > 0) {
    if (typeof DUOSHUO !== 'undefined') DUOSHUO.EmbedThread('.ds-thread');
    else $.getScript("//static.duoshuo.com/embed.js");

比如,回调评论数目

if ($('.ds-thread-count').length > 0) {
    if (typeof DUOSHUO !== 'undefined') DUOSHUO.EmbedThread('.ds-thread-count');
    else $.getScript("//static.duoshuo.com/embed.js");

其他的回调方法同样类似。把回调的函数填到pjax:complete的事件中就可以。比较简单,不再赘述。

注:之前发现这个方法,一直懒得更,后来发现,这儿早有一篇介绍这个的文章了~http://www.4zen.top/ajaxed-load-duoshuo-count/ 如果想了解更多,可以去这儿再去看看看。

最后修改:2019 年 03 月 23 日
喜欢我的文章吗?
别忘了点赞或赞赏,让我知道创作的路上有你陪伴。