那么,这个工程一样SA票 - 这可能是一个有点更简洁,但我真的需要回去工作;-)
<a href="#vote" id="vote-up-%1$d" class="vote vote-up">vote up</a>
<span class="votes">0</span>
<a href="#vote" id="vote-down-%1$d" class="vote vote-down">vote down</a>
和jQuery的:
$(document).on('click', '.vote-up', function() {
if(!$(this).hasClass('vote-locked')){
var votes = parseInt($(this).parent().find('.votes').text());
if(!$(this).hasClass('vote-off')){
$(this).addClass('vote-off');
$(this).nextAll('a').addClass('vote-locked');
votes++;
}
else{
$(this).removeClass('vote-off');
$(this).nextAll('a').removeClass('vote-locked');
votes--;
}
$(this).parent().find('.votes').text(votes);
}
});
$(document).on('click', '.vote-down', function() {
if(!$(this).hasClass('vote-locked')){
var votes = parseInt($(this).parent().find('.votes').text());
if(!$(this).hasClass('vote-off')){
$(this).addClass('vote-off');
$(this).prevAll('a').addClass('vote-locked');
votes--;
}
else{
$(this).removeClass('vote-off');
$(this).prevAll('a').removeClass('vote-locked');
votes++;
}
$(this).parent().find('.votes').text(votes);
}
});
http://jsfiddle.net/gqDgL/
来源
2012-08-22 13:59:13
m7o
你尝试过什么吗? –
给我们一些javascript代码,这样我们就可以看到你在发布问题之前已经挠了脑袋 – 2619
你的意思是“if response success”?我看到你的问题中没有发布ajax。 – jbabey