首页 > Web开发 > 详细

jquery添加类

时间:2014-12-12 18:40:15      阅读:268      评论:0      收藏:0      [点我收藏+]

一.addClass() 方法向被选元素添加一个或多个类。

1.对P元素添加一个intro类。
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>addClass</title>
<script type="text/javascript" src="jquery-git2.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(‘button‘).click(function(){
$(‘p‘).addClass(‘intro‘); //$(‘p:first‘).addClass(‘intro‘);
});
});
</script>
<style type="text/css">
.intro
{
font-size:120%;
color:red;
}
</style>
</head>

<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<button>向第一个 p 元素添加一个类</button>
</body>
</html>

2.添加多个类的时候就是在你addClass() 这个函数中用空格隔开就OK。
3.addClass(function(n){}) 也可以是一个函数。

jquery添加类

原文:http://www.cnblogs.com/kobigood/p/4160242.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!