简体   繁体   English

Facebook Like按钮Jquery Javascript

[英]Facebook Like button Jquery Javascript

I have a little problem hopefully someone can help with :) 我有一个小问题,希望有人可以提供帮助:)

I have a Facebook like button on a page , that I would like to, when 'clicked' to display a form underneath it. 想在页面上有一个类似于Facebook的按钮 ,当我单击该按钮以在其下方显示一个表单时,我想这样做。 So far I have tried .click and it doesn't work, however, .hover does! 到目前为止,我已经尝试过.click ,它不工作,但是, .hover呢! But I don't want it that way. 但是我不想要那样。

Any info would be greatly appreciated! 任何信息,将不胜感激!

(for testing purposes the like button doesn't refer to any page yet, also for facebook script to work needs to be on a server, localhost or otherwise) (出于测试目的,like按钮尚未指向任何页面,同样要使facebook脚本正常工作,必须位于服务器,本地主机上或其他位置)

Here is my code: 这是我的代码:

 <!-- Add Jquery -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>

 <!--My styles -->
   <style>
    #form{display: none;width:400px;}

    </style>

 <!-- Facebook Code -->
    <div id="fb-root"></div>
    <script>(function(d, s, id) {
      var js, fjs = d.getElementsByTagName(s)[0];
      if (d.getElementById(id)) return;
      js = d.createElement(s); js.id = id;
      js.src = "https://connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.8";
      fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));
    </script>

 <!-- MY click Event -->
         <script>
            $(document).ready(function(){
                $(".fb-like").click(function(){ //click doesnt work, hover does
                    $("#form").css("display","block");
                });
             });

            </script>

    <!-- the Button -->
    <div class="fb-like" data-href="#" data-layout="button_count" data-action="like" data-size="large" data-show-faces="false" data-share="false"></div>

   <!-- The Form -->
   <form id="form">
        <input type="text" name="name" value="First Name"><br>
        <input type="email" name="email" value="Your Email">
        <button type="submit" name="submit" value="submit">Sign Up</button>
    </form>

A scratch my previous answer. 从头开始我以前的答案。 I looked again and found out that the like button is rendered in an iframe. 我再次查看后发现,类似按钮在iframe中呈现。 That means it is protected by first origin policy and you CANNOT access DOM components on another domain. 这意味着它受到第一个原始策略的保护,并且您不能访问另一个域上的DOM组件。 Tough luck. 倒霉。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM