我想讓用戶點擊網站上顯示的圖片,目前,圖片是從數據庫,並在一個循環。如果我設置一個ID,用戶只能點擊顯示的第一個圖片,無論如何爲$("#HELP").click(function(){
允許我有一個代碼,但允許所有的圖片點擊?
<div id = 'HotelContentsmallpic'>
<?php
$cols=4; // Here we define the number of columns
echo "<table>"; // The container table with $cols columns
do{
echo "<tr>";
for($i=1;$i<=$cols;$i++){ // All the rows will have $cols columns even if
// the records are less than $cols
$row=mysqli_fetch_array($result2);
if($row){
$img = $row['IMG'];
$cat = $row['Category'];
?>
<td>
<table>
<tr align="top">
<td><img id = "HELP" src="images/Hotel/<?php echo $img ?>.jpg" class="img-responsive" /></td>
<td>
</td>
<td width="50"> </td> <!-- Create gap between columns -->
</tr>
</table>
</td>
<?php
}
else{
echo "<td> </td>"; //If there are no more records at the end, add a blank column
}
?>
<script>
$(document).ready(function(){
$("#HELP").click(function(){
window.location='hotels.php?Category=<?php echo $cat ?>&Pic=<?php echo $img ?>';
});
});
</script>
<?php
}
} while($row);
echo "</table>";
?>
</div>
YESSSS IT WORKS THANKS ^^您的生活救星 – Melvin
提到不是,現在選擇了最好的答案和標記爲已接受,因爲這將有助於其他誰面臨這個問題。 @Melvin – devpro