.wxml
<view class="select_box"> <scroll-view scroll-x="true" style="white-space:nowrap" class="nav_select"> <text class="select_item {{currentTab==index?'red':''}}" wx:for="{{likes}}" wx:key bindtap='selected_tap' data-index='{{index}}' data-current='{{index}}'> {{item.title}} </text> </scroll-view> <view class="selected_view {{currentTab==index?'show':''}}" current='{{currentTab}}' wx:for="{{likes}}" wx:key > {{item.text}} </view> </view>
.wxss
.selected_view{
display: none;
}
.red{
color:red;
}
.show{
display: block;
}
.js
Page({ data:{ likes:[ {title:'排行',text:'22'}, { title: '推荐', text: '22' }, { title: '游戏·', text: '12' }, { title: '穿越', text: '2' }, { title: '恋爱', text: '22' }, { title: '耽美', text: '22' }, { title: '玄幻', text: '22' }, { title: '古风', text: '22' }, { title: '都市', text: '22' }, { title: '修真', text: '22' } ], currentTab:0 }, selected_tap:function(e){ console.log(e) var that=this; if (that.data.currentTab === e.target.dataset.current){ return false }else{ that.setData({ currentTab: e.target.dataset.current}) } console.log(e.target.dataset.index); } })
纸上学来终觉浅,绝知此事要躬行
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· .NET Core 中如何实现缓存的预热?
· 三行代码完成国际化适配,妙~啊~
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
2017-05-11 javascript之存储数据-cookie,localStorage,sessionStorage