Live example: http://jsbin.com/uwigo4/3 (资料来源如下)
查阅“活性”文本,请使用text
:
var text = $( div.tabs li.active ).text();
正在做的改动是:http://api.jquery.com/removeClass/“rel=”removeClass
和>>>>>>>>>>>>>> 例如:
jQueryObjForCurrentActiveElement.removeClass( active );
jQueryObjForNewElementToMakeActive.addClass( active );
如果你在一次活动中重复这样做,奇怪的是,你想要hasClass。
www.un.org/Depts/DGACM/index_spanish.htm 资料来源:。
<!DOCTYPE html>
<html>
<head>
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<meta charset=utf-8 />
<title>Test Page</title>
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<script type= text/javascript >
jQuery(function($) {
$( div.tabs > ul > li ).click(function(event) {
var $this = $(this);
if (!$this.hasClass( active )) {
display("Activating " + $this.text() + " ");
$( div.tabs li.active ).removeClass( active );
$this.addClass( active );
}
});
function display(msg) {
$( <p> + msg + </p> ).appendTo(document.body);
}
});
</script>
<style>
article, aside, figure, footer, header, hgroup,
menu, nav, section { display: block; }
.active {
font-weight: bold;
background-color: #eee;
}
</style>
</head>
<body>
<div class= tabs >
<ul>
<li class= active ><span>Tab 1</span></li>
<li><span>Tab 2</span></li>
<li><span>Tab 3</span></li>
</ul>
</div>
</body>
</html>