我有一个问题,通过单击列表组id_amici我从数据库发送id并插入addClass(),通过再次单击我发送新id的问题,我不能使用.removeClass()函数删除以前的id,我该怎么做?谢谢你
----- HTML PHP --------
$query_logo ="SELECT `ph_banner` FROM `fli_foto_utente` WHERE `id-utente`= '" . $id_utente . "'";
$rs_logo = mysql_query ($query_logo, $conn);
$check_foto = false;
while( $rows_logo = mysql_fetch_assoc($rs_logo) ) {
if ( $rows_logo['ph_banner'] == 'logo' ) {
$check_foto = true;
}
}
$img_user = "assets/img/user.png";
if ( $check_foto ) {
$img_user = "assets/upload/foto_utente/id_ph_" . $id_utente . "/" . $rows_logo['foto-utente'];
} else {
switch ( $rows_utente['genere'] ) {
case 'maschile':
$img_user = "assets/img/man.png";
break;
case 'femminile':
$img_user = "assets/img/girl.png";
break;
case 'altro':
default:
$img_user = "assets/img/user.png";
break;
}
}
?>
<a href="#" class="list-group-item list-group-item-action" id="ev-chat_<?php echo $rows_amici['amici_id']; ?>" data-id_amici="<?php echo $rows_amici['amici_id']; ?>">
<span class="chat-img"> <img src="<?php echo $img_user; ?>" alt="" class="img-fluid" ></span> <?php echo $nomeandcogn; ?>
</a>
<?php
}
----- Jquery ------
$('[id*="ev-chat_"]').click(function() {
var clickCount = 0;
var id_amici = $(this).data("id_amici");
$('#ev-chat_' + idamici).removeClass("active-plus");
clickCount++;
if (clickCount != String(1)) {
$('#ev-chat_' + id_amici).prev().removeClass('active-plus');
}else if (clickCount == String(1)){
$('#ev-chat_' + id_amici).addClass('active-plus');
}
});
字符串
1条答案
按热度按时间nqwrtyyt1#
该
clickCount
始终为1
。$('#ev-chat_' + idamici).removeClass("active-plus");
变量idamici
,而不使用_
。