【问题标题】:How to set up a Twitter follow button that will enable another button after following如何设置 Twitter 关注按钮,该按钮将在关注后启用另一个按钮
【发布时间】:2016-02-14 18:46:55
【问题描述】:

我正在尝试为我的网站设置关注系统,但它似乎无法正常工作。 我正在尝试添加一个 Twitter 关注按钮,该按钮将在单击后启用另一个按钮。

<html>
<head>
    <script>
        function enableButton2() {
            document.getElementById("button2").disabled = false;
        }
    </script>
</head>
<body>
<a href="https://twitter.com/appsboss7" class="twitter-follow-button" data-show-count="false" data-size="large">Follow @appsboss7</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs'); onclick="enableButton2()" </script>
    <input type="button" id="button2" value="button 2" disabled />
</body>
</html>

有人知道怎么解决吗? 提前谢谢, Appsboss7

【问题讨论】:

    标签: javascript html css twitter


    【解决方案1】:

    你的问题是你试图把这个:onclick="enableButton2() 放在脚本标签内。

    onclick 事件应附加到来自 twitters API 的呈现按钮。

    但是,由于该按钮是在页面加载时呈现的,因此您必须在页面加载后以某种方式附加它。

    最简单的解决方案是为此使用 jquery。

    例子:

    <script>
    $( document ).ready(function() {
        $( '#your-twitter-button-id-here' ).click(function() {
            enableButton2();
        });
    });
    <script>
    

    【讨论】:

    • 您好 henrik,该解决方案导致 Twitter 按钮在关注那里提到的人后禁用自身。你知道如何使它也启用第二个按钮吗?因为代码似乎不起作用。这里有 2 个屏幕截图显示发生了什么:prntscr.com/92l2avprntscr.com/92l2ep希望你能帮我解决这个问题,谢谢。
    【解决方案2】:

    你可以试试这个:

    <body>
    <a href="https://twitter.com/appsboss7" class="twitter-follow-button" data-show-count="false" data-size="large">Follow @appsboss7</a>
    <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs'); onclick="enableButton2()" </script>
        <input type="button" id="button2" value="button 2"  />
    </body>
    

    DEMO HERE

    【讨论】:

    • 您好,代码无效。它只是在单击并关注 Twitter 帐户之前启用第二个按钮。感谢您尝试提供帮助!
    猜你喜欢
    • 2013-01-25
    • 2011-09-08
    • 1970-01-01
    • 2012-06-08
    • 1970-01-01
    • 2020-02-01
    • 1970-01-01
    • 2017-12-24
    • 1970-01-01
    相关资源
    最近更新 更多