如何在html中点击按钮后更换body的背景图片?就是简单换肤操作?

<body>

<div style=" float:left; width:100px; height:50px;">
<input type="button" id="changeStyle" " value="皮肤1" onClick="changeStyle()"/></div>
</body>

第1个回答  2015-11-23
==,写代码中。追问

我需要在中加入一个像这样的函数,能帮帮忙吗

function changestyle(num){ document.style.backgroundImage="url("+num+".jpg)";
document.style.backgroundImage="url("+num+".jpg)";
}

追答<script language="JavaScript" type="text/JavaScript">
    
        function showdiv(parent){

          var parent = document.getElementById("parent");
 
          if (parent.className=="ba"){
            parent.className="bb";
 

        } else {
             parent.className="ba"
             }

        }
</script>

<body id="parent">
 
<div style=" float:left; width:100px; height:50px;">
<input type="button" value="黑色" onclick="showdiv('contentid','showtext')" id="aa" />

 </div>

</body>

 

<style>
  .ba{background: #000;}
  .bb{background: #FFF;}
</style>

追问

黑色能变成b.jpg吗?

追答

改成 background: url(img/xxxx.png);

本回答被提问者采纳
相似回答