标签:script html head parent func nbsp put NPU font
js改变或添加className
<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>
标签:script html head parent func nbsp put NPU font
原文地址:https://www.cnblogs.com/taohuaya/p/9577688.html