4

ユーザーが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

4 に答える 4

3

+1タグcallbackパラメータを使用して、非表示機能を起動します。+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

于 2011-06-06T15:40:57.560 に答える
0

HTML5と同等の構文を試してみてください。

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

全体として、レンダリングされたHTMLが注目に値します。

于 2011-06-06T15:36:37.443 に答える
0

これはあなたが必要としているものだと思いますが、ページの最後のすぐ上に置いてください</body>

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

それ以外の場合はこれを試してください...

$('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>
于 2011-06-06T15:35:46.293 に答える
0

ボタンは、アクセスできないiframeにレンダリングされます。タグはiframeを使用<g:plusone>したJSに置き換えられており、live()やbind()などのjQueryを介してこのボタンを監視することはできません。ここにあるボタンの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>
于 2011-06-06T15:40:59.877 に答える