Javascript Style - 如何使用!important标志通过DOM设置CSS属性

<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
#test {
  padding: 1em;
  font-size: 50px;
  font-weight: bold;
  color: red !important;
}
</style>
</head>
<body>
  <div id="test">This is a test</div>
  <script type='text/javascript'>
var elem = document.getElementById('test');
elem.style.setProperty( 'color', 'green', 'important' );

</script>
</body>
</html>

 

posted @ 2022-03-24 09:01  奔跑的太阳花  阅读(200)  评论(0编辑  收藏  举报