当我单击再见项目时, div class=page_bye 应更改为 div class=page_bye1 和 div class=page_home1 的类应更改为 page_home 当我单击主页时,类为 page_home 的 div 应更改为 page_home1 和 page_bye应更改为 page_bye1。但是 div 的样式没有切换 .plz 帮助
<body>
<aside>
<div class=sidebar>
<ul class=nav>
<li class="home1">HOME</li>
<li class="bye">BYE</li>
</ul>
</div>
</aside>
<article>
<div class="page_home1">
<div class="myhome">
<h1>Home</h1>
<p> this is the index page </p>
</div>
</div>
<div class="page_bye">
<div class="mybye">
<h1>Goodbye</h1>
<p> this is bye page </p>
</div>
</div>
</article>
<script>
var regex = /1$/
$("ul.nav li").on('click', function(e) {
var $this = $(this), clazz = $this.attr("class");
var pageclazz="page_"+$this.attr('class');
e.preventDefault();
if(!regex.test(clazz)){
$this.removeClass(clazz).addClass(clazz + 1);
var pagedisplay = "page_"+$this.attr("class");
$("article div").removeClass(pageclazz).addClass(pagedisplay);
$this.siblings('[class$="1"]').attr('class', function(idx, clazz){
return clazz.substring(0, clazz.length - 1)
});
$("article div").siblings('[class$="1"]').attr('class', function(idx, pageclazz){
return pageclazz.substring(0, pageclazz.length - 1)
});
}
});
</script>
</body>
我的CSS是
body {
width:1020px;
margin:0 auto;
position:absolute;
}
aside{
float:left;
display:block;
width:20%;
}
article {
float:right;
display:block;
margin-top:0;
width:75%;
}
.page_home{
visibility:hidden;
}
.page_bye{
visibility:hidden;
}
.page_home1{
visibility:visible;
}
.page_bye1{
visibility:visible;
}
.sidebar {
margin-left:10px;
}
.nav {
display:block;
margin-top:60px;
}
ul {
list-style-type:none;
color:#000;
}
li.home{
background: #666 no-repeat;
width:150px;
height:65px;
color:#000;
}
li.bye{
background:#666 no-repeat;
width:150px;
height:65px;
color:#000;
}
li.home:hover {
background:#06F no-repeat;
width:150px;
height:65px;
color:#000;
}
li.bye:hover {
background:#06F no-repeat;
width:150px;
height:65px;
color:#000;;
}
li.home1 {
background:#06F no-repeat;
width:150px;
height:65px;
color:#000;
}
li.bye1 {
background:#06F no-repeat;
width:150px;
height:65px;
color:#000;
}