📄 10.16 改变slsect选中项的颜色特效.htm
字号:
<html>
<head>
<title>改变选中项的颜色</title>
</head>
<body >
<script language="javascript">
function setColor(_parent, _child) {
for (var i=0; i<_parent.options.length; i++) {//遍历所有选项
if (_parent.options[i] == _child) {
_parent.options[i].style.color = 'yellow'; //颜色
_parent.options[i].style.backgroundColor = 'blue'; //背景色
} else {
_parent.options[i].style.color = ''; //取消颜色
_parent.options[i].style.backgroundColor = ''; //取消背景色
}
}
document.body.focus(); //窗体获得焦点
}
</script>
<select onchange="setColor(this, options[selectedIndex]);">
<option style="color:yellow; background-color:blue;">选项1</option>
<option>选项2</option>
<option>选项3</option>
<option>选项4</option>
<option>选项5</option>
</select>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -