2019独角兽企业重金招聘Python工程师标准>>>
效果如下,点那个那个获取样式,之前已经有样式的取消。
代码如下,我是在菜鸟教程上在线编辑的,所以就这样喽~
if判断不加也行
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>菜鸟教程(runoob.com)</title>
<script src="http://cdn.static.runoob.com/libs/jquery/1.10.2/jquery.min.js">
</script>
<style type="text/css">
.type
{font-weight:bold;font-size:xx-large;
}
</style> <script>
$(document).ready(function(){$("li").click(function(){$("li").each(function(){if($(this).attr("class")!=null)$(this).removeClass("type");});$(this).addClass("type");});});
</script>
</head>
<body>
<ul>
<li class="type">Coffee</li>
<li>Milk</li>
<li>Soda</li>
</ul>
</body>
</html>