2
나는 quest_row, quest_image 및 quest_text의 세 행 그룹으로 구성된 테이블을 보유하고 있습니다. 처음에는 quest_row 만 볼 수 있습니다. 질문 번호를 보여줍니다. 사용자가 테이블의 quest_row 행을 클릭하면 다음 quest_image 및 quest_text 행이 표시됩니다. 코드는 다음과 같습니다.테이블 행을 클릭 할 때 테이블 행을 표시하는 데 문제가 있습니다.
<table width="90%">
<tr>
<td>Questions <?php echo "how many = $how_many"; ?>
</td>
</tr>
</table>
<?php
for ($i=1;$i<=$how_many;$i++) {
$row=mysqli_fetch_assoc($result);?>
<table name="quest_info" id="quest_info" border=1 width="100%">
<tr class="quest_row">
<td bgcolor="#00CCFF">
Question# <?php echo $i; ?>
</td>
</tr>
<?php if ($row["image"] <> NULL) { ?>
<tr class="quest_image" >
<td class="quest_image" id="quest_image<?php echo $i; ?>">
<img src="<?php $pic = $row['image']; echo $base_path . $pic; ?>" width="200" />
</td>
</tr>
<tr class="quest_text" >
<td class="quest_text" id="quest_text<?php echo $i; ?>"><?php echo $row["question"]; ?></td>
</tr>
</table>
<?php
} else {
?>
<tr class="quest_image" >
<td class="quest_image" id="quest_image<?php echo $i; ?>">
</td>
</tr>
<tr class="quest_text" >
<td class="quest_text" id="quest_text<?php echo $i; ?>"><?php echo $row["question"]; ?></td>
</tr>
</table>
<?php
} ?>
<?php
} ?>
<script type="text/javascript" src="../jquery/jquery/jquery-1.7.2.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".quest_text").hide();
$(".quest_image").hide();
$("#quest_info").click(function(){
var trigger = event.target;
alert('target = ' + target);
if(trigger.className == 'quest_row')
{
$(trigger).closest('tr').next('quest_image').show();
$(trigger).closest('tr').next('quest_text').show();
}
});
});
</script>
이것이 작동하지 않는 이유는 확실하지 않습니다.
사용해보십시오 테이블 행을 숨기고하지만 내가 전에 그것을 사용하고 난 많은 jsfiddle 예에 사용되는 거의 정확한 과정을 볼 때 JQuery와 문제가 있습니다. –
DIV와 함께 작동하는지 확인하십시오. 그렇다면 JQuery와 작동하지 않는 테이블입니다. 내가 전에 비슷한 것을하고있을 때 나는 테이블 행을 숨기는 데 어려움을 겪었던 것을 기억합니다. 그러나 div로 전환하고 모두 잘되었습니다. – Mattigins
그래서 div 요소를 tr 요소에 넣으시겠습니까? –