var abc = function() { var fbtg = document.getElementsByClassName('ft-bg'); if (fbtg.length > 0) { for (var i=0;i<fbtg.length;i++) { fbtg[i].parentNode.removeChild(fbtg[i]); } } var newEle = document.createElement('div'); newEle.setAttribute('style', 'background:gray;100%;height:10000px;position:absolute;top:0px;left:0px;'); newEle.setAttribute('class', 'ft-bg'); var c = ''; var a = document.getElementsByTagName('a'); for (var i=0; i < a.length; i++) { var temp = a[i].innerHTML; var houzhui = ['.png','.jpg','.jpeg']; var hasHouzhui = false; for (var j=0; j < houzhui.length; j++) { if (temp.indexOf(houzhui[j]) != -1) { hasHouzhui = true; } } if (hasHouzhui) { c += '<a href="'+a[i].innerHTML+'"><img style="40px;" src="'+a[i].innerHTML+'"/></a>'; } } newEle.innerHTML = c; var body = document.getElementsByTagName('body'); //console.info(newEle, body[0]); body[0].appendChild(newEle); return 'run success'; }; abc();