mui的选项卡js选中指定项

时间:2022-04-01 06:26:21

dom结构:在一定条件下想默认选中第二个选项卡

mui的选项卡js选中指定项mui的选项卡js选中指定项
<div id="segmentedControl" class="mui-segmented-control mui-segmented-control-inverted mui-segmented-control-negative addressslider" style="border-bottom:1px solid #CCC;">
<a class="mui-control-item mui-active" href="#item1">
选择地址
</a>
<a class="mui-control-item" href="#item2" id="header2">
新增地址
</a>
</div>

<div id="item1" class="mui-control-content mui-active" style="height:320px;">
<div class="mui-scroll-wrapper">
<div class="mui-scroll">
第二个选项卡,有滚动
</div>
<!--<div class="mui-scrollbar mui-scrollbar-vertical" style="transition-duration: 500ms; opacity: 0;"><div class="mui-scrollbar-indicator" style="transition-duration: 0ms; display: block; height: 25px; transform: translate3d(0px, 0px, 0px) translateZ(0px); transition-timing-function: cubic-bezier(0.165, 0.84, 0.44, 1);"></div></div>
--> </div>
</div>
<div id="item2" class="mui-control-content" style="height:320px;">
第二个选项卡
</div>
View Code

 

亲测可用

 
//模拟第二个选项卡点击
mui.trigger(document.getElementById("header2"),'touchstart');
mui.trigger(document.getElementById("header2"),'tap');

注意:

mui.trigger 第一个参数应该是dom对象,如果用jq需要转换成dom

依次触发touchstart  tap两个事件才可以