引用:http://zhidao.baidu.com/question/88934003.html
提示:把代码保存为a.htm即可预览效果
<script>
function setDivBG(s)
{
document.getElementById("div1").className=s;
}
</script>
<head>
<style type="text/css">
.style1
{
width: 100px;
height: 100px;
background-image:url('http://img.baidu.com/img/logo-zhidao.gif');
}
.style2
{
width: 100px;
height: 100px;
background-image:url('http://img.baidu.com/img/iknow/images/r1s1g5.gif');
}
</style>
</head>
<BODY >
<select onchange="setDivBG(this.value);">
<option value="style1">知道</option>
<option value="style2">头像</option>
</select>
<div id="div1" class="style2" >
</div>
</BODY>