id와 class의 처리방법 채택완료
현재 원글을 클릭 시 해당 답변글이 뜨게하는 소스를 만들고있는 도중에 궁금해서 글을 올립니다.
<ul>
<?php for ($i=0; $i<count($list); $i++) {
$reply_href = G5_BBS_URL.'/write.php?w=r&bo_table='.$bo_table.'&wr_id='.$list[$i]['wr_id'].$qstr;
echo "<a target='iframe_show' class='latest_st' id='main_1' href=\"".$list[$i]['href']."\">";
if($is_admin) {
if(!$list[$i]['wr_reply'])
echo " ".$list[$i]['subject']."<a target='iframe_show' class='first_re' href='".$reply_href."'>추가</a>";
} else {
if(!$list[$i]['wr_reply'])
echo " ".$list[$i]['subject']."";
}
echo "</a>";
?>
<li>
<?php
if($is_admin){
if($list[$i]['wr_reply']){
echo "<a target='iframe_show' onclick='sink2(this)' id='sub_1' class='latest_re' href=\"".$list[$i]['href']."\" >".$list[$i]['icon_reply']." ";
echo $list[$i]['subject']."";
echo "<a target='iframe_show' class='second_re' href='".$reply_href."'>추가</a>";
}
}
else{
if($list[$i]['wr_reply']){
echo "<a target='iframe_show' onclick='sink2(this)' id='sub_1' class='latest_re'href=\"".$list[$i]['href']."\" >".$list[$i]['icon_reply']." ";
echo $list[$i]['subject']."";
}
}
echo "</a>";
?>
</li>
</ul>
소스는 이런상태이구요. 원글과 답변글에 각각 class와 id를 하나씩 줬습니다.
그래서 스크립트를 이용하여 show, hide를 하고 있었는데
class로 하면 모든 답변글이 삭제가 되는데 id로 하면 최상위 넘버에 있는 답변 글만 삭제가 됩니다.
스크립트는 똑같이 했구요.
$(function(){
$('#main_1').click(function(){
$('#sub_1').hide();
$('.second_re').hide();
});
});
$(function(){
$('.latest_st').click(function(){
$('.latest_re').hide();
$('.second_re').hide();
});
});
왜 두가지가 다르게 표현이 되는건지 알고 싶습니다.
답변 3개
답변을 작성하려면 로그인이 필요합니다.
로그인