2016-08-30 7 views
0

Google +1ボタンの2回目のクリックを禁止します。Google +1ボタンの2回目のクリックを禁止する方法

<g:plusone callback='click_callback' href="myurl.com"></g:plusone> 

click_callback機能は次のとおりです。

function click_callback(b) { 
    if(b.state == "on") { 
    $.ajax({ 
     type: "POST", 
     url: "gp1process.php", 
     data: "id=" + id, 
     cache: false, 
     success: function(a) { 
     $("#Hint").html(a); 
     remove(id); 
     click_refresh() 
     } 
    }) 
    } 

私はjQueryののone()方法を使用することはできますか?

+3

学ぶための良い方法は、それが – cnorthfield

+1

'のjQuery( 'click_callbackを ')動作するかどうかをテストすることであるもの(' クリック'、関数(E){click_callback(E);} ); ' –

+1

ダブルクリックまたは複数回のクリックを防止したいですか? – happymacarts

答えて

2

私は実際にajaxリクエストに投稿していないので、私は$(this).attr("disabled", "disabled")をajaxコールの前に置いていましたが、あなたの成功関数でそれを望みます。

ボタンをクリックすると、disabled = "disabled"属性がボタンに追加されます。私はそれがあなたが探していたものだと思います。

$(document).ready(function() { 
 
    $('button').click(click_callback); 
 
}); 
 

 
function click_callback(b) { 
 
    id = $(this).attr('id'); 
 
    if (!$(this).attr("disabled")) { 
 
    //the line below should be in your success function 
 
    //i placed it here so you can see the feature work 
 
    //since i am not really running the ajax 
 
    $(this).attr("disabled", "disabled") 
 
    $.ajax({ 
 
     type: "POST", 
 
     url: "gp1process.php", 
 
     data: "id=" + id, 
 
     cache: false, 
 
     success: function(a) { 
 
     $(this).attr("disabled", "disabled") 
 
     $("#Hint").html(a); 
 
     remove(id); 
 
     click_refresh() 
 
     } 
 
    }) 
 
    } else { 
 
    //the button is diabled do something else 
 

 
    } 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<g:plusone callback='click_callback' href="myurl.com"></g:plusone> 
 
<button id="theID">+1</button> 
 

 
<div id="hint"></div>

+0

Googleの代わりにを使用した理由は? @happymacarts –

関連する問題