latest.skin.php 관련 질문입니다!!

latest.skin.php 관련 질문입니다!!

QA

latest.skin.php 관련 질문입니다!!

본문


<?php
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가
include_once(G5_LIB_PATH.'/thumbnail.lib.php');
run_event('bbs_good_before', $bo_table, $wr_id, $good);
// add_stylesheet('css 구문', 출력순서); 숫자가 작을 수록 먼저 출력됨
add_stylesheet('<link rel="stylesheet" href="'.$latest_skin_url.'/style.css">', 0);
$thumb_width = 297;
$thumb_height = 212;
$list_count = (is_array($list) && $list) ? count($list) : 0;
?>
 
<div class="pic_li_lt">
   
<h2 class="lat_title"><a href="<?php echo get_pretty_url($bo_table); ?>"><?php echo $bo_subject ?></a></h2>
 
    <ul>
    <?php
    for ($i=0; $i<$list_count; $i++) {
       
        $img_link_html = '';
       
        $wr_href = get_pretty_url($bo_table, $list[$i]['wr_id']);
        //좋아요
        $good_href = G5_BBS_URL.'/good.php?bo_table='.$bo_table.'&wr_id='.$list[$i]['wr_id'].'&good=good';
        //싫어요
        $nogood_href = G5_BBS_URL.'/good.php?bo_table='.$bo_table.'&wr_id='.$list[$i]['wr_id'].'&good=nogood';
 
    ?>
   
        <li>
            <?php echo $img_link_html; ?>
            <?php
            if ($list[$i]['icon_secret']) echo "<i class=\"fa fa-lock\" aria-hidden=\"true\"></i><span class=\"sound_only\">비밀글</span> ";
 
            echo "<a href=\"".$wr_href."\" class=\"pic_li_tit\"> ";
           
            if ($list[$i]['ca_name']) {
                echo  "<span class =\"lt_ca\">" ."[{$list[$i]['ca_name']}]". "</span>";
            }
 
            if ($list[$i]['is_notice'])
                echo "<strong>".$list[$i]['subject']."</strong>";
            else
                echo $list[$i]['subject'];
       
                    echo "</a>";
 
 
        ?>
 
 
            <div class="lt_info">
 
         <?php  
 
//  if ($list[$i]['wr_id'].'&good=good') {
    if ($list[$i]['wr_good'] == 0){  
    echo "<a href=\"".$good_href."\"  id=\"lt_good\" class=\"lt_v_good\">" . "<span class=\"lt_good\"><i class=\"fa fa-heart-o\"></i>" ."<strong>{$list[$i]['wr_good']}</strong>". "</span>";        
    echo "<b id=\"lt_v_act_good\"></b>";
    echo "</a>";
    }
    else{
        echo "<a href=\"".$good_href."\"  id=\"lt_good\" class=\"lt_v_good\">" . "<span class=\"lt_good\"><i class=\"fa fa-heart\"></i>" ."<strong>{$list[$i]['wr_good']}</strong>". "</span>";        
         echo "<b id=\"lt_v_act_good\"></b>";
        echo "</a>";
    }
    echo "<span class=\"lt_cmt\"><i class=\"fa fa-comment-o\"></i>" .$list[$i]['wr_comment']."</span>";
    ?>

 
<?php }  ?>
 
<script>
$(function() {
    // 추천, 비추천
    $("#lt_good").click(function() {
        var $tx;
        if(this.id == "lt_good")
            $tx = $("#lt_v_act_good");
 
        excute_good(this.href, $(this), $tx);
        return false;
    });
});
</script>
 
<script>
function excute_good(href, $el, $tx)
{
    $.post(
href,
        { js: "on" },
        function(data) {
if(data.error) {
alert(data.error);
                return false;
            }

 
if(data.count) {
    $el.find("strong").text(number_format(String(data.count)));
}
 
if(data.msg){
    $tx.stop().hide();
    $tx.text(data.msg);
    $tx.fadeIn(200).delay(2500).fadeOut(200);
}

 
        }, "json"
    );
}
</script>

 
 
    <?php if ($list_count == 0) { //게시물이 없을 때  ?>
    <li class="empty_li">게시물이 없습니다.</li>
    <?php }  ?>
    </ul>
    <!-- <a href="<?php echo get_pretty_url($bo_table); ?>" class="lt_more"><span class="sound_only"><?php echo $bo_subject ?></span>더보기</a> -->
 
</div>
</script>

 

991484400_1658998915.9405.png

처음 게시물은 저렇게 좋아요 버튼을 누르면 이글을 추천 하셨습니다라는 문구가 뜨는데

 

그 아래의 게시물을 좋아요를 누르면 

991484400_1658998974.6388.png

이런식으로 문구가 뜨는데 어떻게 수정을 해야 할 지 모르겠습니다.

 

 

이 질문에 댓글 쓰기 :

답변 3


문제는 동일한 id 여러개로 되어있어서 제대로 실행을 할 수없어서 입니다
echo "<a href=\"".$good_href."\" id=\"lt_good\" <---- 이 id가 list목록수 만큼 나올 것 아닙니까?
view페이지처럼 좋아요버튼이 한번만 나올 때에 사용하는 것을 리스트에다 옮겨놓았는데 제대로 될 수가 없습니다
id는 삭제하고 아래코드처럼 class로 작동 되도록 수정 해야하는데
테스트를 안해봐서 정확히 작동할지는 모르겠습니다
echo "<b id=\"lt_v_act_good\"></b>"; 
수정==>
echo "<b class=\"lt_v_act_good\"></b>";
------------------------------------------
  $("#lt_good").click(function() {
        var $tx;
        if(this.id == "lt_good")
            $tx = $("#lt_v_act_good");
수정 ===>
  $(".lt_v_good").click(function() {
            $tx = $(this).children(".lt_v_act_good");
 

 

 

음...일단 원인은 위 내용으로는 찾을수 없으나 의심되는 상황은 자바스크립트 이벤트를 아이디값에 주셨네요

아이디는 1개 페이지에서 1개만 존재하는 유니크한 값인데... 코드를 보니 아마 저 좋아요 버튼이 리스트배열만큼 출력되고 그만큼의 같은 id를 가진 것들이 많을것으로 보여요. 그래서 처음 클릭한 엘리먼트와 나중에 클릭한 엘리먼트를 같은 엘리먼트라고 판단해서 처음 클릭했던 엘리먼트를 기준으로 이벤트가 작동하는거 같아요

답변을 작성하시기 전에 로그인 해주세요.
전체 123,129 | RSS
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT