需要加载jQuery库
HTML代码:
<!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=utf-8" />
<script src="js/jquery.js"></script>
<title>无标题文档</title>
<style>
.add{
background:blue;
}
</style>
</head>
<body>
<a href="javascript:void(0)" onclick="click_dome(1)" id="id1">大</a>
<a href="javascript:void(0)" onclick="click_dome(2)" id="id2">中</a>
<a href="javascript:void(0)" onclick="click_dome(3)" id="id3">小</a>
<div class="content" id="content">
abckefghijklmnopqrstuvwsyz
</div>
</body>
</html>
jQuery代码:
<script type="text/javascript">
function click_dome(n){
var a = document.getElementById("content");
if(n==1){
$("#id2").removeClass('add');
$("#id3").removeClass('add');
$("#id1").addClass('add');
a.style.fontSize="16px";
}else if(n==2){
$("#id1").removeClass('add');
$("#id3").removeClass('add');
$("#id2").addClass('add');
a.style.fontSize="14px";
}else{
$("#id1").removeClass('add');
$("#id2").removeClass('add');
$("#id3").addClass('add');
a.style.fontSize="12px";
}
}
</script>