zoukankan      html  css  js  c++  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 .fontWeight
    12 {
    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     //删除单个class=""样式
    28     //div1.className = div1.className.replace(/fontSize22/,"");
    29     //删除所有class=""样式
    30     //div1.removeAttribute("class");
    31     //删除style=""中的单个样式
    32     div1.style.cssText = div1.style.cssText.replace(/red/,"blue");
    33     //删除style=""中的所有样式
    34     //div1.style.cssText = "";
    35 }
    36 </script>
    37 </body>
    38 </html>
  • 相关阅读:
    集合合并
    非递减有序集合合并
    有序的双链表的实现
    单链表的实现
    构造有序的单链表
    约瑟夫环问题
    javaweb学习笔记
    Intellij IDEA快捷键
    JAVA:创建类和对象
    JAVA:成员变量和局部变量的区别
  • 原文地址:https://www.cnblogs.com/cag2050/p/5187426.html
Copyright © 2011-2022 走看看