星空网 > 软件开发 > Java

javascript操作class和style样式

 1 <!doctype html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title>无标题文档</title> 6 <style> 7 .fontSize22 8 { 9   font-size:22px;10 }11 .fontWeight12 {13   font-weight:bold;14 }15 </style>16 </head>17 18 <body>19 <div id="div1" class="fontSize22 fontWeight" style="color:red">div实例文本</div>20 <button onclick="changeStyle()">changeStyle()</button>21 <script>22 function changeStyle()23 {24   var div1 = document.getElementById("div1");25   //div1.className = "fontSize22";26   //div1.className += " fontWeight";27   //删除单个样式28   //div1.className = div1.className.replace(/fontSize22/,"");29   //删除所有样式30   //div1.removeAttribute("class");31   //删除中的单个样式32   div1.style.cssText = div1.style.cssText.replace(/red/,"blue");33   //删除中的所有样式34   //div1.style.cssText = "";35 }36 </script>37 </body>38 </html>

 




原标题:javascript操作class和style样式

关键词:JavaScript

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

Morphe:https://www.goluckyvip.com/tag/23118.html
Morrisons:https://www.goluckyvip.com/tag/23119.html
农药类产品:https://www.goluckyvip.com/tag/2312.html
Moses外贸助手:https://www.goluckyvip.com/tag/23120.html
MOSISO:https://www.goluckyvip.com/tag/23121.html
Moss:https://www.goluckyvip.com/tag/23122.html
石象湖景区门票-石象湖景区门票优惠政策:https://www.vstour.cn/a/411243.html
北京到嵩山自驾游沿途景点 北京距离嵩山有多远:https://www.vstour.cn/a/411244.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流