我需要帮助保存这个,我可以交换图像但不能保存它们。我在想也许是一个更新按钮来存储图像。或者在进行更改时自动保存。有人提到饼干什么的。我不熟悉 cookie,想要一个更简单的解决方案。实际页面将有大约 100 张图像,并且确实需要保存功能以永久保存更改。
希望有人能弄清楚这一点,已经在这几个小时才能做到这一点提前感谢您只是看这个
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>Swap demo</title>
<style type="text/css">
#GALLERY td {
height: 200px; width: 200px;
text-align: center;
vertical-align: middle;
}
#GALLERY td img, #GALLERY td img.normal {
border: solid white 5px;
}
#GALLERY td img.highlighted {
border: solid red 5px;
}
</style>
</head>
<body>
<table id="GALLERY">
<tr>
<td>
<img src="http://www.clearviewarts.com/thumbnails/Puppy In Basket.jpg" alt="Dogs"/>
</td>
<td>
<img src="http://www.clearviewarts.com/thumbnails/BabyIndy.jpg" alt="Dogs"/>
</td>
<td>
<img src="http://www.clearviewarts.com/thumbnails/HarlequinDane.jpg" alt="Dogs"/>
</td>
</tr>
<tr>
<td>
<img src="http://www.clearviewarts.com/thumbnails/Pug.jpg" alt="Dogs"/>
</td>
<td>
<img src="http://www.clearviewarts.com/thumbnails/Wagner-edit1.jpg" alt="Dogs"/>
</td>
<td>
<img src="http://www.clearviewarts.com/thumbnails/CanusAngelicus.jpg" alt="Dogs"/>
</td>
</tr>
</table>
<script type="text/javascript">
var pix = document.getElementById("GALLERY").getElementsByTagName("img");
for ( var p = 0; p < pix.length; ++p )
{
pix[p].onclick = picclick;
}
var firstImage = null;
function picclick( )
{
// to cancel a swap, click on first image again:
if ( firstImage == this )
{
this.className = "normal";
firstImage = null;
return;
}
// is this first image clicked on?
if ( firstImage == null )
{
// yes
firstImage = this;
this.className = "highlighted";
return; // nothing more to do
}
// aha! second image clicked on, so do swap
firstImage.className = "normal";
var temp = this.src;
this.src = firstImage.src;
firstImage.src = temp;
firstImage = null;
}
</script>
</body>
</html>