javascript - jQuery html 在刷新时消失

标签 javascript jquery html refresh

我正在修改一个空的<div>.html() jQuery 的方法。当我刷新页面时,添加的代码消失。

$('#div').html($('#div').html() + '<div>'+obj.name+'&nbsp;<a href="">(x)</a>');

是否可以改变行为或使用其他方法?

谢谢

编辑:

验证我的问题

Maybe it is a design error. It is a form with some fields and a second form where the user can upload files, after a file is uploaded i add the filename and a delete link in a div. If the user submits the form the program connects the created object and the files. It is not really a page where anybody should need to refresh, but it can happen and then the files are saved in the database but the information is lost to connect it with the form object.

最佳答案

当然,每当您重新加载页面时,所有元素都会返回到原始状态(从服务器加载时)。不过,有一些方法可以解决这个问题。

  • 使用 cookie
  • 使用 HTML 本地存储

您必须了解客户端脚本的工作原理。修改发生在客户端系统上,而不是在服务器上,从服务器加载脚本。

关于javascript - jQuery html 在刷新时消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10463489/

相关文章:

jquery ajax 忽略 500 状态错误

html - 在 bootstrap 3 上用视频定位 div

javascript - 每个 Ajax 数据

javascript - 图标在 Leaflet Easy Button 中的位置

javascript - 绘制条形图后Chartjs条形顺序调整

javascript - JavaScript中多级对象数组的简化

javascript - 使用 JavaScript 在 src 或 href 属性上附加时间戳

javascript - jQuery:输入元素的类型不支持选择

HTML 表单文件上传不上传文件

html - 文本在图像上方而不是在图像下方