日期:2014-05-16 浏览次数:20423 次
<html>
<head>
</head>
<body>
<div id="header">
<a href="#">1111111</a><br />
<a href="#">2222222</a><br />
<a href="#">3333333</a><br />
</div>
<div id="main">
<div class="1">1111111</div>
<div class="2">2222222</div>
<div class="3">3333333</div>
</div>
</body>
</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" />
<title>无标题文档</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<style type="text/css">
a.on{color:#f00}
#main div.on{background-color:#f00;display:block;}
#main div{display:none;}
</style>
</head>
<body>
<div id="header">
<a id="anchor1" class="on" href="#">1111111</a><br />
<a id="anchor2" href="#">2222222</a><br />
<a id="anchor3" href="#">3333333</a><br />
</div>
<div id="main">
<div id="anchor1_main" class="on">1111111</div>
<div id="anchor2_main">2222222</div>
<div id="anchor3_main">3333333</div>
</div>
<script type="text/javascript">
jQuery(function($){
$('a').click(function(){
var att=$(this).attr('id');
var attmain='#'+att+'_main';
$('#header').find('a').not($(this)).removeClass('on');
$(this).addClass('on');
$('#main').find('div').not($(attmain)).removeClass('on');
$(attmain).addClass('on');
});
});
</script>
</body>
</html>