使用jquery为指定元素添加样式类
分类:实例代码
本章节演示一下如何利用jquery为制定的元素添加样式类。
代码实例如下:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="author" content="http://www.pipipi.net/" /> <title>前端教程网</title> <style type="text/css"> .p{ width:300px; height:100px; text-align:center; line-height:100px; background:#ccc; } </style> <script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script> <script> $(document).ready(function(){ $("#bt").click(function(){ $("p").addClass("p"); }); }); </script> </head> <body> <p>前端教程网欢迎您</p> <input type="button" id="bt" value="查看效果"/> </body> </html>
一线大厂高级前端编写,前端初中阶面试题,帮助初学者应聘,需要联系微信:javadudu