<style type="text/css"> .newDiv { font-weight: bold; } </style>
js和html
<script> function clk() { var parent = document.getElementById("parent"); // parent.className = parent.className + " newDiv"; //添加classname 既html中的div 的class变为 class = "google newDiv" parent.className = " newDiv"; //改变classname 既html中的div 的class变为 class = "newDiv" } </script> </head> <body> <input type="button" value="click" onclick="clk();"/> <div id="parent" class="google"> <div >child</div> </div> </body>
原文地址:https://www.cnblogs.com/taohuaya/p/9577688.html
时间: 2024-11-19 00:44:40