我正在尝试更改整个文档的背景颜色,这应该可行。改变文字应该是一样的吗?我一直在搞乱代码,我还没有找到一种简单的方法来编写代码。
<style>
function bgPick()
{
if(document.displayOptions.value == 1){
body.background-color:blue;
}
else if(document.displayOptions.value == 2){
body.background-color:cyan;
}
else{
body.background-color:white;
}
}
</style>
<form name="displayOptions">
<select name="colorPick" onchange="bgPick()">
<option value=0>Background Color</option>
<option value=1>Blue</option>
<option value=2>Cyan</option>
<option value=3>White</option>
</select>
<select name="textPick">
<option value=0>Font Color</option>
<option value=1>Black</option>
<option value=2>Red</option>
<option value=3>Silver</option>
</select>
</form>
答案 0 :(得分:1)
答案 1 :(得分:0)
RASG是对的,你应该在尝试实现类似的东西之前先阅读一个JavaScript教程......
<script>
function bgPick() {
var select = document.querySelector("select[name='colorPick']"),
color;
switch (select.value) {
case "1": color = "blue"; break;
case "2": color = "cyan"; break;
default: color = "white"; break;
}
document.body.style.backgroundColor = color;
}
</script>