解决方法:document.getElementById('test').className = 'emphasis'

Eg:

<!doctype html>
<html lang="zh-cn">
 <head>
  <meta charset="UTF-8">
  <title>Test</title>
  <style type="text/css">
    p { 
    color: #000000; /* black */ 
    } 
    p.emphasis { 
    color: #cc0000; /* red */ 
    } 
  </style>
 </head>
 <body>
    <p id="test">Test</p>
    <hr>
    <input type="button" value="修改className为emphasis" onclick="document.getElementById('test').className = 'emphasis';">
    <input type="button" value="修改className为空" onclick="document.getElementById('test').className = '';">
 </body>
</html>

 

相关文章:

  • 2021-12-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-07
  • 2021-05-28
  • 2022-02-02
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-02-11
  • 2021-12-06
  • 2022-02-04
  • 2021-12-09
相关资源
相似解决方案