mui.fire()
为什么在 mui.fire() 触发的事件里面,改变 tab 高亮样式,样式改变了,但是实际效果却没有高亮?
页面切换成功了,我将 tab 样式打印出来,是有 mui-active 样式的,但并没有高亮
上一个页面代码:
var selfWv = plus.webview.currentWebview();
mui.fire(mainPage, 'mainShow',{id:selfWv.type});
setTimeout(function() {
selfWv.close();
}, 300)
主页面代码:
document.addEventListener('mainShow', function(event) {
var id = event.detail.id;
var defaultTab = document.getElementById(id);
mui.trigger(defaultTab, 'tap');
//切换选项卡高亮
var current = document.querySelector(".mui-bar-tab>.mui-tab-item.mui-active");
if (defaultTab !== current) {
current.classList.remove('mui-active');
defaultTab.classList.add('mui-active');
console.log(current.classList) // 输出:mui-tab-item
console.log(defaultTab.classList) // 输出:mui-tab-item mui-active
//样式更换了,但是没有高亮效果
}
});
1 个回复
8***@qq.com
我之前也遇到过着问题
var btn = document.getElementsByClassName("mui-tab-item")[1];
mui.trigger(btn, 'tap');
var parent = btn.parentNode;
var chlidren = parent.children;
for(var i = 0; i < chlidren.length; i++) {
chlidren[i].classList.remove("mui-active");
}
chlidren[1].classList.add("mui-active");