日期:2014-05-16 浏览次数:20445 次
<!DOCTYPE HTML> <html> <head> <meta charset="gb2312" /> <title></title> </head> <body> <div id="test" style="width:120px; height:120px;"></div> <script> function $(el){ return typeof el == 'string' ? document.getElementById(el) : el; } var img = new Image; img.src = 'http://avatar.profile.csdn.net/D/2/3/2_yiqiejieruying.jpg'; img.onload = function(){ $('test').style.backgroundImage = 'url('+img.src+')'; } </script> </body> </html>