jquery와 같은 버튼을 쓰고 있지만 조건에 문제가 있습니다.jquery는 조건이있는 경우 텍스트/숫자를 올바르게 변경하지 않습니다.
내가 가진다른 문제는 TOTAL_LIKES의 카운터입니다 : 내가 좋아하는 버튼을 클릭 카운터가 0으로 설정되어 달리 클릭하지만 난 다시 좋아하는 경우에 테 카운터가 ... 2 대신에 1
PHP는 간다 경우/HTML :
if (total_likes > 0) {
$hide = 'block';
} $hide = 'none';
$photos_box .= '<input type="hidden" class="tl' . $imgID . '" value="' . $total_likes . '" />
<a id="' . $imgID . '" class="like_button" title="' . $like_title . '">' . $like . '</a>
//the counter
<a id="" style="display: '. $hide . '">
<span id="color" class="mod' . $imgID . '">' . $total_likes . '</span>
</a>
// the text
<li id="counter" style="display: ' . $hide . ';">
<div id="">
<span class="text_color">' . $text . '</span>
</div>
</li>
JQuery와 스크립트 :
$('.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 <a id="A_112">other</a> like this.');
} else if (total_likes > 2) {
var tl = total_likes+1;
$('.text_color').html('You and <a id="A_112">'+tl+' others</a> 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('<a id="A_112">1 person</a> like this.');
} else if (total_likes > 2) {
var tl = total_likes-1;
$('.text_color').html('<a id="A_112">'+tl+' people</a> 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);
});
});
JQuery와 실시간으로 변경 작업 내가 조건문이 무엇을 필요로하는지 할 올바른지 확실하지 않다 ... 엉망입니다. 하고있다 -2 like_counter + 1은 2를하고있다 like_counter-1 왜
나는 내가 잘못 무엇
... 몰라?
솔직히var total_likes = $('.mod'+this.id).html();
'경우 (TOTAL_LIKES> 0) { $는 = '블록'을 숨기기; } $ hide = 'none'; '의미가 없습니다 – epascarello
왜? 만약 내가 좋아하지 않는다면 그걸 보여주고 싶지 않아. 아이콘이없고 숫자/텍스트가없는 빈 공간입니다. –
음, 코드에 따르면 모든 것이 숨겨집니다. 그게 내가 본 적이없는 이상한 PHP 구문이 아니라면 말이다. – epascarello