简体   繁体   中英

Changing <select>'s Background Color

I don't understand why the following isn't changing the select's background color. It's probably something simple, but I can't see it. I'm using Notepad++ editor with Chrome and Opera browsers.

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>Debugging</title>
    <style >
        select {
          background-color: #FF0000;
        }

    </style>
    <script>

      function myFunction() {
        document.getElementById('slct').style.backgroundColor = #FFFFFF;
      }

    </script>
  </head>
  <body>
    <select id="slct">
      <option>Choose</option>
      <option>The First Choice</option>
      <option>The Second Choice</option>
    </select>

    <input type="button" onclick="myFunction()" value="Click Me!">
  </body>
</html>

Check your browser's console, you might be getting errors. Background-color value must be in quotes.

document.getElementById('slct').style.backgroundColor = "#FFFFFF";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM