摘要:table切换在各个网页中经常用到,平常用jQuery比较容易实现,使用jQuery中的siblings选择其余同胞元素。希望阅读本篇文章以后大家有所收获,帮助大家对jQuery的理解更加深入。
table切换在各个网页中经常用到,平常用jQuery比较容易实现,使用jQuery中的siblings选择其余同胞元素。
<div id="tit">
<span class="select">标题1</span>
<span>标题2</span>
<span>标题3</span>
</div>
<ul id="con">
<li class="show">内容111</li>
<li>内容222</li>
<li>内容333</li>
</ul>
$('#tit span').click(function() { var i = $(this).index();//下标第一种写法 //var i = $('tit').index(this);//下标第二种写法 $(this).addClass('select').siblings().removeClass('select'); $('#con li').eq(i).show().siblings().hide(); });
<h4 ref="all" @click="all">全部</h4><h4 ref="product" @click="product">商品</h4><h4 ref="news" @click="news">新闻</h4>
用vue实现方法
<div id="app">
<div>
<button v-for="(ind,key,index) in btn" v-bind:class="{active:(indexs==index)}"
v-on:click="a(index)">{{ind}}</button>
//这段代码通过indexs==index的值来判断active类,通过a方法来决定indexs 的值 反正以我的水平是写不出来的
</div>
<div class="wrap">
<div v-for="(w,key,index) in box" v-if="indexs == index">{{w}}</div>
</div></div>
<script type="text/javascript">
var app = new Vue({ el:"#app", data:{ btn:{a:"按钮1",b:"按钮2",c:"按钮3"}, box:{aa:"tab切换1",bb:"tab切换2",cc:"tab切换3"}, indexs:0, a:function(str){ this.indexs=str; } } })</script> .wrap div{ width: 300px; height: 300px; background-color: #0cc; }.active{ background-color: red }
代码中内容部分来自box中的数据。
本文由职坐标整理并发布,了解更多内容,请关注职坐标WEB前端jQuery频道!
您输入的评论内容中包含违禁敏感词
我知道了
请输入正确的手机号码
请输入正确的验证码
您今天的短信下发次数太多了,明天再试试吧!
我们会在第一时间安排职业规划师联系您!
您也可以联系我们的职业规划师咨询:
版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
沪公网安备 31011502005948号