按钮没有通过js函数改变css样式?

问题描述 投票:0回答:1
html css function button styles
1个回答
0
投票

看起来你的代码工作正常

<!DOCTYPE html>
<html>
  <head> </head>
  <body>
    <button id="button1">image</button>
    <p id="dropdown">Hello bob</p>
    <script>
      function openNav() {
        document.querySelector('#dropdown').style.color = 'red';
      }
      document.getElementById('button1').addEventListener('click', openNav);
    </script>
  </body>
</html>

© www.soinside.com 2019 - 2024. All rights reserved.