如何通过标签“选择”来改变背景图像 [英] How to change the background image through the tag "selected"
本文介绍了如何通过标签“选择”来改变背景图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试使用下拉菜单更改正文的背景图片(id =shelf):
I'm trying to change the background image of the body (id = "shelf") using a drop-down menu:
<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>
但我不知道为什么它不工作..代码中的问题在哪里?
But I don't know why it doesn't work.. Where's the problem in code?
推荐答案
正常。
function changeTheme() {
var e = document.getElementById("themes");
var theme = e.options[e.selectedIndex].value;
document.getElementById("shelf").style.backgroundImage = "url(" + theme + ")";
}
这篇关于如何通过标签“选择”来改变背景图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文