好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

HTML5的classList属性操作CSS类的使用详解

这篇文章主要介绍了详解使用HTML5的classList属性操作CSS类,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>classList</title>
    <style>
        .mystyle {
            width: 300px;
            height: 50px;
            background-color: red;
            color: white;
            font-size: 25px;
        }
    </style>
</head>
<body>

<p>点击按钮为p元素添加 "mystyle" 类。</p>
<button onclick="myFunction()">点我</button>
<p id="myp">
    我是一个 p 元素。
</p>
<script>
    function myFunction() {
        document.getElementById("myp").classList.add("mystyle");
    }
</script>

</body>
</html> 
  //returns true or false
 document.getElementById("myp").classList.contains("myp"); 

以上就是HTML5的classList属性操作CSS类的使用详解的详细内容,更多请关注Gxl网其它相关文章!

查看更多关于HTML5的classList属性操作CSS类的使用详解的详细内容...

  阅读:48次