
图1,当链接a处于激活状态,并且选中1,假定在链接a已经选定了1了,要在链接b选择出1之外的数字,要怎么判定,求解
<meta charset="UTF-8">
<title>文字限定字数</title>
<style>
.wrap{
margin: 100px 50px;
}
.nav{
margin-left: 50px;
}
.nav a{
text-decoration: none;
}
.nav a.on{
color: red
}
ul li{
width: 250px;
height: 250px;
background: #ddd;
color: #fff;
float: left;
margin-right: 50px;
line-height: 250px;
text-align: center;
font-size: 50px;
border:1px solid #ccc;
}
ul li.active{
border:1px solid red;
}
</style>
<p class="nav">
<a href="#">链接a</a>
<a href="#">链接b</a>
</p>
<p>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
</p>
<script src="http://cdn.bootcss.com/jquery/3.1.1/jquery.min.js"></script>
<script>
$(function(){
$(".nav a").on("click",function(){
$(this).addClass('on').siblings().removeClass('on');
$("ul li").unbind("click").click(function(){
$(this).addClass('active').siblings().removeClass('active');
})
})
})
</script>
图2:现在代码只是写到这里,按照逻辑应该是错的,求正解
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
你是想点链接b然后选中那些未选中的然后原来已选中的移除active吗
用了checked来标示a链接的时候选中的。如果a、b链接没有前后顺序的化,你可以var个中间量来判断是不是第一次点击链接,再做判断。