我正在创建一个小型投票机制,通过AJAX发送快速数据库时间戳.
一系列具有"投票"类别的按钮是投票的触发器,而下面的文本显示该特定项目的"投票"数量.
从click事件运行AJAX方法后,我删除了"vote"类,使得该项不能有多个.但是我的问题是,即使删除了类,触发器仍然可以触发并增加投票数.
这是元素的HTML:
<div class="points">
<img class="vote" src="images/up.gif" alt="'.$idea['id'].'">
<p class="vote-'.$idea['id'].'">'.$points.' Points</p>
</div>
Run Code Online (Sandbox Code Playgroud)
这是jQuery调用:
$('.vote').click(function(){
var iID = $(this).attr('alt');
var typeString = "id="+iID;
$.ajax({
type: "POST",
url:"vote.php",
data: typeString,
success: function (txt){
$('.vote-'+iID).html('<p>'+txt+' Points</p>');
}
});
$(this).attr('src', 'images/voted.gif');
$(this).removeClass('vote');
});
Run Code Online (Sandbox Code Playgroud)