修改!important定义的样式(2)
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <meta name="viewport" content="width=device-width, initial-scale=1.0"> 6 <meta http-equiv="X-UA-Compatible" content="ie=edge"> 7 <title>Document</title> 8 <style> 9 .test { 10 background: red !important; 11 } 12 </style> 13 </head> 14 <body> 15 <div class="test" style="background: yellow !important;"> 16 <div class="container"> 17 我是一个测试 18 </div> 19 </div> 20 21 22 23 24 <script src="./jquery-3.2.1.min.js"></script> 25 <script> 26 var sts = $(".test").attr("style") + 'background:blue !important;'; 27 $(".test").css("cssText", sts); 28 console.log($(".test")); 29 </script> 30 </body> 31 </html> 32
最终的背景色为蓝色,需要的朋友可以直接复制代码查看效果