以下代码检索3张图像并显示在表格中!我已经导入了必要的jquery库和css脚本来实现灯箱模式!但它不起作用请帮助我!我如何纠正代码?
<?php
require("includes/db.php");
$sql="SELECT * FROM `order` ";
$result=mysqli_query($db,$sql);
echo"<head>";
echo"<link rel='stylesheet' href='image.css'>";
echo"</head>";
echo "<body bgcolor=#E6E6FA>";
echo "<table border=1 cellspacing=0 cellpadding=4 > " ;
while($row=mysqli_fetch_array($result))
{
echo"</td>";
echo"<td align=center >";
echo '<a href='.( $row['Image1'] ).' >';
echo "</a>";
echo "<img id='myImg1' src='" .$row['Image1']. "' height='180' width='150' />";
echo "<br>";
echo"</td>";
echo"<td align=center >";
if($row['Image2']=="No copy"){
echo "No copy";
}
else{
echo '<a href='.( $row['Image2'] ).' >';
echo "</a>";
echo "<img id='myImg2' src='" . $row['Image2'] . "' height='180' width='150' />";
}
echo "<br>";
echo"</td>";
echo"<td align=center >";
if($row['Image3']=="No copy"){
echo "No copy";
}
else{
echo '<a href='.( $row['Image3'] ).' >';
echo '</a>';
echo "<img id='myImg3' src='" . $row['Image3'] . "' height='180' width='150' />";
}
echo "<br>";
echo"</tr>";
}
echo "</table>";
echo '<div id="myModal" class="modal">
<span class="close">×</span>
<img class="modal-content" id="img02">
<div id="caption"></div>
</div>';
echo "<script>
// Get the modal
var modal = document.getElementById('myModal');
// Get the image and insert it inside the modal - use its 'alt' text as a caption
var img = document.getElementById('myImg1');
var modalImg = document.getElementById('img02');
var captionText = document.getElementById('caption');
img.onclick = function(){
modal.style.display = 'block';
modalImg.src = this.src;
captionText.innerHTML = this.alt;
}
// Get the <span> element that closes the modal
var span = document.getElementsByClassName('close')[0];
// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.style.display = 'none';
}
var modal = document.getElementById('myModal');
// Get the image and insert it inside the modal - use its 'alt' text as a caption
var img = document.getElementById('myImg2');
var modalImg = document.getElementById('img02');
var captionText = document.getElementById('caption');
img.onclick = function(){
modal.style.display = 'block';
modalImg.src = this.src;
captionText.innerHTML = this.alt;
}
// Get the <span> element that closes the modal
var span = document.getElementsByClassName('close')[0];
// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.style.display = 'none';
}
var modal = document.getElementById('myModal');
// Get the image and insert it inside the modal - use its 'alt' text as a caption
var img = document.getElementById('myImg3');
var modalImg = document.getElementById('img02');
var captionText = document.getElementById('caption');
img.onclick = function(){
modal.style.display = 'block';
modalImg.src = this.src;
captionText.innerHTML = this.alt;
}
// Get the <span> element that closes the modal
var span = document.getElementsByClassName('close')[0];
// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.style.display = 'none';
}
</script>";
?>
相关的css文件(image.css)如下
#myImg1 {
border-radius: 5px;
cursor: pointer;
transition: 0.3s;
}
#myImg2 {
border-radius: 5px;
cursor: pointer;
transition: 0.3s;
}
#myImg3 {
border-radius: 5px;
cursor: pointer;
transition: 0.3s;
}
#myImg1:hover {opacity: 0.7;}
#myImg2:hover {opacity: 0.7;}
#myImg3:hover {opacity: 0.7;}
/* The Modal (background) */
.modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 1; /* Sit on top */
padding-top: 100px; /* Location of the box */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
overflow: auto; /* Enable scroll if needed */
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0,0.9); /* Black w/ opacity */
}
/* Modal Content (image) */
.modal-content {
margin: auto;
display: block;
width: 80%;
max-width: 700px;
}
/* Caption of Modal Image */
#caption {
margin: auto;
display: block;
width: 80%;
max-width: 700px;
text-align: center;
color: #ccc;
padding: 10px 0;
height: 150px;
}
/* Add Animation */
.modal-content, #caption {
-webkit-animation-name: zoom;
-webkit-animation-duration: 0.6s;
animation-name: zoom;
animation-duration: 0.6s;
}
@-webkit-keyframes zoom {
from {-webkit-transform:scale(0)}
to {-webkit-transform:scale(1)}
}
@keyframes zoom {
from {transform:scale(0)}
to {transform:scale(1)}
}
/* The Close Button */
.close {
position: absolute;
top: 15px;
right: 35px;
color: #f1f1f1;
font-size: 40px;
font-weight: bold;
transition: 0.3s;
}
.close:hover,
.close:focus {
color: #bbb;
text-decoration: none;
cursor: pointer;
}
/* 100% Image Width on Smaller Screens */
@media only screen and (max-width: 700px){
.modal-content {
width: 100%;
}
}
</style>
.lightbox:target {
/** Remove default browser outline */
outline: none;
/** Unhide lightbox **/
display: block;
}
目前灯箱模式仅适用于检索到表格的第一行图像,但不适用于其他图像?是什么原因 ?我怎么能纠正它?