Skip to content

Instantly share code, notes, and snippets.

@FrankFan
Created April 23, 2014 08:49
Show Gist options
  • Save FrankFan/11207588 to your computer and use it in GitHub Desktop.
Save FrankFan/11207588 to your computer and use it in GitHub Desktop.
js set option background color
<html>
<head>
<title>Javascript quiz</title>
<meta charset="utf-8">
<script type="text/javascript">
/*
* 要求:
* how to use js to set the backgournd color of the
* sencond option(value="b") to be grey?
*/
function setColor () {
var option = document.getElementsByTagName("option");
option[1].style.backgroundColor = "gray";
}
</script>
</head>
<body>
<div>
<select>
<option value="a">Hello</option>
<option value="b">World</option>
</select>
<input type="button" value="set color" onclick="setColor()">
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment