<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
<script type ="text/javascript" >
function optionColor()
{
var oSel=document .getElementById("muchColor");
var oOp=oSel .getElementsByTagName ("option");
for (var i=0;i<oOp .length ;i++)
{
oOp[i].onmouseover=function (){this.className+='backColor';}
oOp[i].onmouseout=function (){this.className=this.className.replace("backColor","");}
}
}
</script>
<style type ="text/css" >
.backColor{ background-color :Red ; color:Yellow;}
</style>
</head>
<body onload ="optionColor()">
<form id="form1" runat="server">
<div>
<select id="muchColor" name="id1">
<option value="red">红</option>
<option value="blue">蓝</option>
<option value="green">绿</option>
<option value="purple">紫</option>
<option value="black">黑</option>
</select></div>
</form>
</body>
</html>
<head runat="server">
<title>无标题页</title>
<script type ="text/javascript" >
function optionColor()
{
var oSel=document .getElementById("muchColor");
var oOp=oSel .getElementsByTagName ("option");
for (var i=0;i<oOp .length ;i++)
{
oOp[i].onmouseover=function (){this.className+='backColor';}
oOp[i].onmouseout=function (){this.className=this.className.replace("backColor","");}
}
}
</script>
<style type ="text/css" >
.backColor{ background-color :Red ; color:Yellow;}
</style>
</head>
<body onload ="optionColor()">
<form id="form1" runat="server">
<div>
<select id="muchColor" name="id1">
<option value="red">红</option>
<option value="blue">蓝</option>
<option value="green">绿</option>
<option value="purple">紫</option>
<option value="black">黑</option>
</select></div>
</form>
</body>
</html>
var oOp=oSel .getElementsByTagName ("option");对象和方法用逗号连接,咋有空格?
也不对吧?
{
(function(i){
oOp[i].onmouseover=function (){this.className+=' backColor';}
oOp[i].onmouseout=function (){this.className=this.className.replace(" backColor","");}
})(i);
}
背景色是option的背景色还是整个背景色
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
<script type ="text/javascript" >
function optionColor()
{
var oSel=document.getElementById("muchColor");
var oOp=oSel.getElementsByTagName ("option");
oSel.onmouseover=function (){document.getElementById("aaa").style.backgroundColor=oOp[oSel.selectedIndex].value;};
oSel.onmouseout=function (){document.getElementById("aaa").style.backgroundColor="white";};
}
</script>
<style type ="text/css" >
.backColor{ background-color:Red ; color:Yellow;}
</style>
</head>
<body>
<form id="form1">
<div id="aaa" style=" width:100px;height:100px;background:black;margin:10px;">
<select id="muchColor" name="id1" OnChange="optionColor()">
<option value="red">红</option>
<option value="blue">蓝</option>
<option value="green">绿</option>
<option value="purple">紫</option>
<option value="black">黑</option>
</select></div>
</form>
<br>这里是内容。
</body>
</html>
你的hover到的时候 会有蓝色的背景对吧
即使你加上了背景 也会被这个蓝色覆盖的~~没有效果的~
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
<style type ="text/css" >
.backColor{ background-color :Red ; color:Yellow;}
</style>
</head>
<body onload ="optionColor()">
<form id="form1" runat="server">
<div>
<select id="muchColor" name="id1" onchange="document.body.style.backgroundColor=document.getElementById('muchColor').value">
<option value="red">红</option>
<option value="blue">蓝</option>
<option value="green">绿</option>
<option value="purple">紫</option>
<option value="black">黑</option>
</select></div>
</form>
</body>
</html>我想你应该是想要这种效果吧!
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
<style type ="text/css" >
.backColor{ background-color :Red ; color:Yellow;}
</style>
</head>
<body onload ="optionColor()">
<form id="form1" runat="server">
<div>
<select id="muchColor" name="id1" onmouseover="this.className+='backColor'" onfocus="this.className=this.className.replace('backColor',' ')" onblur="this.className='none'">
<option value="red">红</option>
<option value="blue">蓝</option>
<option value="green">绿</option>
<option value="purple">紫</option>
<option value="black">黑</option>
</select></div>
</form>
</body>
</html>
上面这个onload事件忘了去掉了!!!
<head runat="server">
<title>无标题页</title>
<style type ="text/css" >
.backColor{ background-color :Red ; color:Yellow;}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<select id="muchColor" name="id1" onmouseover="this.className='backColor'" onfocus="this.className='backColor'" onblur="this.className=this.className.replace('backColor',' ')">
<option value="red">红</option>
<option value="blue">蓝</option>
<option value="green">绿</option>
<option value="purple">紫</option>
<option value="black">黑</option>
</select></div>
</form>
</body>
</html>