如果存在(不存在)就删除(添加)一个类。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>toggleClass()方法</title>
<style type="text/css">
<!--
p{
color:blue; cursor:help;
font-size:13px;
margin:0px; padding:5px;
}
.b{
color:blue; cursor:help;
font-size:13px;
margin:0px; padding:5px;
}
.highlight{
background-color:#FFFF00;
}
-->
</style>
<script language="javascript" src="jquery-1.4.2.min.js"></script>
<script type="text/javascript">
$(function(){
$("p").click(function(){
//点击的时候不断切换
$(this).toggleClass("highlight");
});
});
</script>
</head>
<body>
<p>高亮?</p>
</body>
</html>