我需要幫助保存這個,我可以交換圖像,但不能保存它們。我想可能是更新按鈕來存儲圖像。或者在更改時自動保存。有人提到了cookies或其他東西。我不熟悉餅乾,並希望有一個更簡單的解決方案。 實際頁面將有大約100張圖片,並且需要保存功能來永久保存更改。需要幫助保存在javascript中的onclick函數的文件
希望有人能想出解決辦法,一直在這幾個小時只走這麼遠 感謝提前時間只盯着這個
<!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>
您需要將其保存,這樣當用戶重新加載頁面時,更改仍然做了什麼?我認爲這個工作的JSFiddle會很棒,所以我可以看到這實際上在做什麼。 – Shawn31313