单击后隐藏加一个按钮

时间:2011-06-06 15:10:23

标签: javascript jquery google-plus-one

我希望在用户使用jQuery点击后隐藏google的+1按钮;这是我正在使用的代码,但它似乎无法正常运行:

JS:

$(function() {
  $("#button").click(function()
  {
    $(".HIDE").hide();
  });

  return false;
});

HTML:

<div class="HIDE">
  <script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>
  <g:plusone size="small" class="plusone"></g:plusone>
</div>

4 个答案:

答案 0 :(得分:3)

使用+1 tag callback parameter触发隐藏功能。可能有更好的方法来选择+1按钮,但这适用于演示。

<g:plusone size="tall" callback="poHide"></g:plusone>
<script src="http://apis.google.com/js/plusone.js"></script>
<script>function poHide(){ $("#___plusone_0").fadeOut(); }</script>

演示:jsfiddle.net/Gju6T

答案 1 :(得分:0)

我认为这就是您所需要的,但请将其放在页面末尾</body>

上方
$('g\\:plusone').live('click',function (){
   $(this).remove();
});

<强> ELSE 试试这个......

$('iframe').contents().find('#plusone').live('click',function (){
       $(this).remove();
    });

<强> orrr

<script>
function mycall(str){
 console.log(str);
 //$(str).hide();//???
}
</script>
<g:plusone size="small" class="plusone" callback="mycall"></g:plusone>

答案 2 :(得分:0)

您可能想尝试HTML5等效语法:

<div class="g-plusone" data-size="standard" data-count="true"></div>

总而言之,渲染的HTML将是值得关注的东西。

答案 3 :(得分:0)

该按钮呈现为您无权访问的iframe。 <g:plusone>标记由JS替换为iframe,您无法通过jQuery观察此按钮,例如使用live()或bind()。您必须使用可以找到here的按钮的API。 在那里你可以找到你可以使用的选项“回调”:

<script type="text/javascript" src="jquery-1.6.1.min.js"></script>
<script type="text/javascript" src="https://apis.google.com/js/plusone.js">
      {"parsetags": "explicit"}
</script>
<script type="text/javascript">
// Call the API method after the page loaded
$(document).ready(function() {
   gapi.plusone.render("HIDE",
       {"size": "standard", "count": "true", "callback" : "hideTheButton"});
});
// Method to remove the element
function hideTheButton() {
   $("#HIDE").hide();
}
</script>
<div id="HIDE">
      <g:plusone></g:plusone>
</div>