应用
在前端开发中,如果有目录,那么肯定会有目录被选中的样式,以区别和其他未选中的目录,下面我来通过JS来实现这一需求
JS
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$(".i").click(function(){
//去除所有菜单的样式
$(".i").removeClass("blue");
//给当前菜单添加样式
$(this).addClass("blue");
});
});
</script>
<style type="text/css">
.important
{
font-weight:bold;
font-size:xx-large;
}
.blue
{
color:blue;
}
</style>
</head>
<body>
<p class="i">这是一个段落。</p>
<p class="i">这是另外一个段落。</p>
</body>
</html>