foreachループ(php)を介してページに表示されているdivがあります。それぞれのdivでは、クリックされたときは、私は1つのdiv内の投票ボタンをクリックしたときに1ずつ増加することになっている投票ボタンは、しかし、1すべての票の増加は、ここに私のjqueryのがありますされていますjQuery 'vote'ボタンはすべての要素に影響します
$(document).ready(function($) {
$.ajax({
url: "index.php",
success: function(data) {
$('.fa-plus').each(function(){
$(this).on('click', function(){
var counter = 0;
counter = counter+1;
$('.votes').html(counter);
})
});
}
})
そして、私の簡略化のために整えた私のマークアップのスニペット:
foreach ($applications as $application){
echo '<div class="widget-main">',
'<span class="pull-right votes" id="votes-count"><strong>0</strong> </span>',
'<h4 class="list-group-item-heading remove-margin"><i class="fa fa- heart fa-fw"></i>'.$votes.' Votes</h4>',
'<h4 class="list-group-item-heading remove-margin"><i class="fa fa-plus fa-fw"></i> Vote for '.$application ->_name.'</h4>',
'</div>';
}
PS私はデータベースに投票を挿入するつもりです。
マークアップを提供した場合は、さらに役立つことがあります。 http://stackoverflow.com/help/how-to-ask –