需要帮助保存javascript中onclick函数中的文件

need help saving file from onclick function in javascript

本文关键字:onclick 函数 文件 javascript 帮助 保存      更新时间:2023-09-26

我需要帮助保存这个,我可以交换图像,但不能保存它们。我在考虑一个更新按钮来存储图像。或者可能在进行更改时自动保存。有人提到饼干什么的。我不熟悉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>

这就是我要做的(我希望这能有所帮助)。

  • 在JS中构建一个图像名称数组(在服务器上)
  • 根据数组(通过JS)渲染HTML
  • 如果用户进行图像交换,请更改阵列,然后重新渲染。
    • 渲染不需要从服务器中提取任何数据,因此不会闪烁
    • onclick事件应该告诉更新函数哪个图像正在被更改
  • 如果要保存显示顺序,请将当前阵列POST回服务器

如果这听起来太复杂,看看这些

  • http://inspiretrends.com/free-jquery-carousel-plugins/
  • http://webdesigntunes.com/freebies/30-amazing-free-jquery-slider-and-carousel-plugins-of-2013/

看看http://owenberesford.me.uk/17690427/sample.html但请注意:

  • 对于"真实"代码,我通常从一个测试用例开始
  • 这在FF和Opera(都是Linux)上运行,没有在任何MSIE上进行测试
  • 为了实现最大的自由度,没有使用任何框架
  • 所有内容都在客户端上运行,因此您只需查看/保存即可