<!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>
<title></title>
<style type="text/css">
p
{
background-color:#eee; font-size:30px;
}
.classadd
{
font-weight:bold; font-family:微软雅黑; font-size:40px; background-color:Green;
}
.classadd1
{
background-color:Red;
}
</style>
<script src="jquery-1.9.1.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$('#btnclass').click(function () {
$('p').css('background-color', 'blue');//设置样式
})
$('#btnAdd').click(function () {
$('p').addClass('classadd classadd1');//添加样式
})
$('#btnRemove').click(function () {
$('p').removeClass('classadd1'); //删除指定名称的样式
})
$('#btnChange').click(function () {
$('p').toggleClass('classadd1');
})
})
</script>
</head>
<body>
<p class="classadd">得用汉字</p>
<input type="button" id="btnclass" value="设置样式" />
<input type="button" id="btnAdd" value="添加样式" />
<input type="button" id="btnRemove" value="删除样式" />
<input type="button" id="btnChange" value="切换样式" />
</body>
</html>
![](https://img2024.cnblogs.com/blog/35695/202408/35695-20240826070647288-243310440.jpg)