要导入的js:
var HTMLElement=HTMLElement?HTMLElement:function HTMLElement(){
};
HTMLElement.prototype.__defineGetter__=HTMLElement.prototype.__defineGetter__?HTMLElement.prototype.__defineGetter__:function(){};
HTMLElement.prototype.__defineGetter__("currentStyle", function () {
return this.ownerDocument.defaultView.getComputedStyle(this, null);
});
var console=console?console:{};
console.log=console.log?console.log:alert;
加载前将有背景图的div,或img隐藏(display:none)
加载成功把图片显示出来的方法如下:
function showPic(self){
var img=document.createElement("img");
var src=self.currentStyle.backgroundImage;
src=src.replace(/[\"|\(|\)]/g,"");
//src=src.replace(/[\(|\)]/g,"");//不去引号,不行
src=src.replace(/url/g,"");
console.log(src);
img.setAttribute("src",src);
//$(img).load(function(){
img.οnlοad=function(){
console.log("pic successful!!!");
self.style.display='block';
};
};
ps:火狐可以,ie暂时不兼容...