<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title></title> <script src="js/JQ3.3.1.js"></script> <link rel="stylesheet" type="text/css" href="css/style.css"/> <script type="text/javascript"> $(function(){//对div添加txt的样式 $(".temp").attr("class","txt");//样式选择器。钱符中填入具体的样式。样式为class在元素中定义 }) </script> </head> <body> <div id="showMsg"><h1>test</h1></div> <div id="showMsg"><h1>test</h1></div> <span class="temp">test</span> <span>test</span> <p class="temp">test</p> <p>test</p> </body> </html>