I want to get the text of just which table data is clicked on. i.e. get $post_no value if clicked on post_no, get the word 'description' if clicked on description. I have tried a number of ways but cannt get what i want. whats the approach?
my php code:
echo "<table border=1>";
echo "<tr><th>Post No</th><th>Writer ID</th><th>Writer Name</th><th>Title</th><th>Description</th><th>Summary</th><th>Approval</th></tr>";
while ($row= mysqli_fetch_array($r2)){
$post_no=$row['post_no'];
$writer_id=$row['writer_id'];
$writer_name=$row['writer_name'];
$title=$row['title'];
$description=$row['description'];
$summary=$row['summary'];
echo "<tr height='50' class='x"."". " '>";
echo "<td class='r'>".$post_no."</td>";
echo "<td class='r'>".$writer_id."</td>";
echo "<td class='r'>".$writer_name."</td>";
echo "<td class='r'>".$title."</td>";
echo "<td class='r'>".'description'."</td>";
echo "<td class='r'>".'summary'."</td>";
echo "<td class='r'>Approve</td>";
echo "</tr>";
}
echo "</table>";
javascript code;
<script>
$(document).ready(function(){
$(".x").each(function(i){
$(this).click(function(){
console.log($(this).children().eq(i).text());
});
});
});
</script>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…