1.添加一个img载体 用来存放背景图片 src是背景图片的路径
<img src="2.jpg" οnlοad="setAutoBack('aa',this)" id="img"
style="width: 1293px;"/>
2.在body里写id="aa" οnresize="setAutoBack('aa','img')" style="overflow:hidden;"
例如:<body id="aa" οnresize="setAutoBack('aa','img')" style="overflow:hidden;" >
3.复制粘贴代码:
<script language="javascript">
function setAutoBack(obj, imgn) {
try {
var img = document.getElementById("img");
var dyback = document.getElementById(obj);
img.style.height = dyback.offsetHeight;
//img.style.left = dyback.offsetLeft;
// img.style.top = dyback.offsetTop;
img.style.width = dyback.offsetWidth;
img.style.zIndex = -1;
}
catch (ee) {
try {
img.style.display = "none";
}
catch (err) {
}
}
}
</script>