请帮助我。
示例我有以下代码的图像,并希望下面的图像在5天后删除,如何进一步编码?
<imgsrc="http://www.quackit.com/pix/milford_sound/milford_sound_t.jpg" style="max-width:100%" alt="Milford Sound in New Zealand" />
应该在此代码中添加什么代码才能在5天后删除此图片?
答案 0 :(得分:0)
删除给定网址的任何(1个或多个)IMG标记:
<img src="http://quackit.com/pix/milford_sound/milford_sound_t.jpg";
style="max-width:100%" alt="Milford Sound in New Zealand" />
通过JavaScript从页面添加以下代码:
<script type='text/javascript'>
function removeThatImg() {
var ex=document.getElementsByTagName("img");
for (var i=0;i<ex.length;i++) {
if ( ex[i].src == "http://quackit.com/pix/milford_sound/milford_sound_t.jpg" )
ex[i].parentNode.removeChild(ex[i]);
}
}
var dateStart = Date.parse('March 16, 2013')/86400000;
var dateNow = new Date();
dateNow = dateNow.getTime()/86400000;
if ( dateNow - dateStart > 5) // more than 5 days
window.onload=function() {
//do it with a half second delay, because google may take time to add that image
//and right after the page is loaded it may not yet be there
setTimeout(removeThatImg,500);
}
</script>
它只是可以工作(或者可能不会 - 我认为情况就是如此,因为每次都会有不同的图像)