JavaScript实现随机更换网页背景图片 首页 » 编程语言 » JavaScript实现随机更换网页背景图片 分享到各大社区 全屏 A JavaScript实现随机更换网页背景,不限图片张数,每刷新一次网页更换一次背景图片。 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> <script type="text/javascript"> bg = new Array(3); //设定图片数量为3,这时候有3张图片用来切换 bg[0] = 'http://www.lijiapei.com/content/templates/BYSB/bg/001.jpg' //显示的图片路径 bg[1] = 'http://www.lijiapei.com/content/templates/BYSB/bg/002.jpg' bg[2] = 'http://www.lijiapei.com/content/templates/BYSB/bg/003.jpg' index = Math.floor(Math.random()*bg.length); document.write("<body background="+bg[index]+">"); </script> </head> <body style="background-repeat:no-repeat;background-attachment:fixed;background-position:center;background-size:cover;"> </body> </html> 标签:JavaScript 版权声明:若无特殊注明,本文皆为( VISAce )收集整理,版权归原作者所有。—— 李佳培.中国
发表评论
既然没有评论,那就赶紧抢沙发吧!