本文实例为大家分享了Javascript实现更换背景图片的具体代码,供大家参考,具体内容如下
主要通过Js控制行内样式,达到更换背景图片的目的
效果:
代码:
更换背景 *{ margin: 0; padding: 0; } body{ background: url(./images/01.jpg) no-repeat; background-size: 600px; } ul{ list-style: none; } ul li{ width: 80px; height: 50px; border: 1px solid #222; float: left; margin: 10px; } ul li img{ width: 80px; height: 50px; cursor: pointer; }
注意:
正确写法: document.body.style.background = “url(”+this.src+") no-repeat";
错误写法: document.body.style.background = "this.src“ no-repeat;
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持考高分网。



