0
附件是我的代碼,我想一個div的背景圖片由JS選擇: 變化backgrooun圖像usingdocument.getElementByClassName
<html lang = "en">
<head>
<title>to-forum.html</title>
<meta charset="utf-8" />
<style>
.logo
{
width:1200px;
height:300px;
margin:auto;
display: block;
background-repeat:no-repeat;
position:relative;
border-radius: 25px;
}
</style>
<script>
function ChangeImage(param)
{
switch(param)
{
case '1':
return("images/greensilver.gif");
break;
case'2':
return("images/greensilver1.gif");
break;
}
}
</script>
</head>
<body>
<div id="logo">
<script>
document.getElementByClassName("logo").style.backgroundImage = "url('" + ChangeImage('1') + "')";
</script>
</div>
</body>
</html>
圖像顯示不出來!任何人都可以告訴我如何更正代碼? 感謝
我們不是代碼編寫服務。請參考[如何提出一個好問題?](https://stackoverflow.com/help/how-to-ask)。你有沒有試過做任何研究?你有什麼嘗試?這裏的問題應該有一個明確的問題/問題,顯示的研究和[最小,完整和可驗證](https://stackoverflow.com/help/mcve)示例。 – GrumpyCrouton