如何清除HTML数据? [英] How to clear HTML data?

查看:364
本文介绍了如何清除HTML数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



< link rel =stylesheettype = text / csshref =stylesheet.css?v = 1.0/>



每当我们改变样式表并且需要浏览器需要清除我们的CSS样式表,我们可以更改版本号,如1.1,1.2等。



有没有什么类似于清除HTML数据的东西?






我有这样的HTML标记:

 < img src =picturename.jpg/><! -  ** man **的图片> 

稍后,我需要更改图片,但相同的文件名

 < img src =picturename.jpg/><! -  **女性的照片**  -  - > 

我删除了男性的照片并上传了女性照片。但是,当我在浏览器中查看时,即使在执行干净刷新(Ctrl + F5)后,仍然显示作为男性照片的缓存图片,并且还会使用浏览器的设置进行清除。



更新






每次清除缓存都不是好主意,所以我想通过jQuery实现这个概念:


  1. 首先将图像src从 picturename.jpg
    picturename.jpg?v = 1

  2. 将号码存储在本地存储或cookie中。但是我对
    使用cookie感到困惑,因为如果用户删除了cookie,那么存储的
    变量也会被删除,因此将它存储在本地存储中
    会是更好的主意。

  3. 检索本地存储变量号并检查全局
    变量数是否超出,然后只更改图片src数
    ,如下所示:






  var cnum = 1; //作者将在需要时更改此数字
$(document).ready(function(){
var ccnum; //存储在本地存储中,然后在cnum大于ccnum时增加数字
//现在将src更改为图像

我需要更改所有图库的src图片 $('#mygallery img')实际上我有数百张图片需要在一段时间后更改,但需要相同的文件名。



我该怎么办?

解决方案

随机数/时间戳,这将导致浏览器重新加载图像,因为它是一个不同的URL,但文件名可以是相同的。

 < img src =picturename.jpg?201401281148/> 


We can clear the CSS style sheet cache by using the query selector like this:

<link rel="stylesheet" type="text/css" href="stylesheet.css?v=1.0" />

Whenever we change the style sheet and need the browsers to be cleared about our CSS style sheet, we could change the version number like 1.1, 1.2, etc.

Is there anything something like this for clearing HTML data?


I was having the HTML markup like this:

<img src="picturename.jpg" /><!--picture of a **man**--->

Later I need to change the picture but the same file name:

<img src="picturename.jpg" /><!--picture of a **woman**--->

I deleted the picture of man and uploaded picture of woman. But when I viewed in the browser it is showing the cached picture that is picture of a man even after very clean refresh (Ctrl+F5) and also clearing with the settings that the browsers have.

Update


I came to know every time clearing the cache is not good idea so I wanted to implement this by jquery with the following concept:

  1. First set the image src from picturename.jpg to picturename.jpg?v=1
  2. Store the number in local storage or in cookie. But I'm confusing to use cookie as if the user deletes the cookies then the stored variable would also be deleted thus storing it in local storage would be better idea.
  3. Retrieve the local storage variable number and check if the global variable number is exceeded then only change the picture src number something like this:


var cnum = 1; // author will change this number when needed
$(document).ready(function(){
var ccnum; // store in local storage then increase the number if cnum is greater than ccnum
//now change the src as of image

I need to change the src of all of my gallery images $('#mygallery img') and actually I've hundreds of images which are to be changed after some time but needed the same file name.

How could I do?

解决方案

You could append a string to the filename with a random number/timestamp, this will cause the browser to reload the image as it's a different URL, however the filename can be the same.

<img src="picturename.jpg?201401281148" />

这篇关于如何清除HTML数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆