0

ドロップダウンメニューを使用して、ボディの背景画像(id = "shelf")を変更しようとしています。

<script type="text/javascript">
function changeTheme()
{document.getElementById("shelf").style.backgroundImage = "url("+theme+")";
  var e = document.getElementById("themes");
  var theme = e.options[e.selectedIndex].value;
}  
</script>
</head>
<body id="shelf">
<select id="themes" onChange="changeTheme()">
  <option value="images/bg/default.png">Default</option>
  <option value="images/bg/oriental.png">Oriental</option>
  <option value="images/bg/office.png">Office</option>
  <option value="images/bg/old.png">Old</option>
</select>
</body>    

しかし、なぜそれが機能しないのかわかりません。コードの問題はどこにありますか?

4

2 に答える 2

0

あなたが見ている行動は正確には何ですか?

これを試して:

<html>
<head>
<script type="text/javascript">
function changeTheme()
{

  var e = document.getElementById("themes");
  var theme = e.options[e.selectedIndex].value;
  console.log(theme);
  document.getElementById("shelf").style.backgroundImage = "url("+theme+")";
}  
</script>
</head>
<body id="shelf">
<select id="themes" onChange="changeTheme()">
  <option value="images/bg/default.png">Default</option>
  <option value="images/bg/oriental.png">Oriental</option>
  <option value="images/bg/office.png">Office</option>
  <option value="images/bg/old.png">Old</option>
</select>
</body>    
</html>
于 2012-12-16T16:11:54.790 に答える
0

動作しています。

function changeTheme() {
    var e = document.getElementById("themes");
    var theme = e.options[e.selectedIndex].value;
    document.getElementById("shelf").style.backgroundImage = "url(" + theme + ")";

}
于 2012-12-16T16:13:13.220 に答える