Я пишу кнопку «Подобная кнопку» с jQuery, но у меня есть некоторые проблемы с условными.if (total_likes > 0) {
$hide = 'block';
} $hide = 'none';
$photos_box .= '
' . $like . '
//the counter
' . $total_likes . '
// the text
[*]
' . $text . '
< /code>
Скрипт jQuery: < /p>
$('.like_button').click(function() {
var total_likes = $('.tl'+this.id).val();
total_likes = parseInt(total_likes);
var status = '';
if ($(this).html() == 'Like') {
status = 'like';
$(this).html('Unlike');
$(this).attr('title', 'Unlike this');
$('.mod'+this.id).html(total_likes+1);
if (total_likes == 0) {
$('#counter').slideToggle('fast');
$('.text_color').html('Like this.');
} else if (total_likes == 1) {
$('.text_color').html('You and other like this.');
} else if (total_likes > 2) {
var tl = total_likes+1;
$('.text_color').html('You and '+tl+' others like this.');
}
} else if ($(this).html() == 'Unlike') {
status = 'unlike';
$(this).html('Like');
$(this).attr('title', 'Like this');
$('.mod'+this.id).html(total_likes-1);
if (total_likes == 0 || total_likes == 1) {
$('#counter').slideToggle('fast');
} else if (total_likes == 2) {
$('.text_color').html('1 person like this.');
} else if (total_likes > 2) {
var tl = total_likes-1;
$('.text_color').html(''+tl+' people like this.');
}
}
var data = {
img_id : this.id,
sta : status
};
$.ajax({
type : 'POST',
url : '/includes/like.php',
data : data
}).done(function(result) {
console.log(result);
});
});
< /code>
Работа с jQuery и изменениями в реальном времени -это беспорядок ... Я не уверен, что условные условия правы, чтобы делать то, что ему нужно.>
Подробнее здесь: https://stackoverflow.com/questions/269 ... conditions