HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Tab 选项卡 - 通过 JavaScript 调用</title>
<link rel="stylesheet" href="https://cdn.w3cbus.com/library/mdui/1.0.2/css/mdui.min.css"/>
</head>
<body style="padding-top: 20px;">
<div class="mdui-container">
<div class="mdui-tab" id="tab">
<a href="#tab1-content" id="tab1" class="mdui-ripple">web</a>
<a href="#tab2-content" id="tab2" class="mdui-ripple">shopping</a>
<a href="#tab3-content" id="tab3" class="mdui-ripple">images</a>
</div>
<div id="tab1-content" class="mdui-p-a-2">web content</div>
<div id="tab2-content" class="mdui-p-a-2">shopping content</div>
<div id="tab3-content" class="mdui-p-a-2">images content</div>
<button id="prev" class="mdui-btn mdui-color-pink-accent mdui-m-a-1">prev</button>
<button id="next" class="mdui-btn mdui-color-pink-accent mdui-m-a-1">next</button>
<br/>
<button id="show-first" class="mdui-btn mdui-color-pink-accent mdui-m-a-1">show first</button>
<button id="show-second" class="mdui-btn mdui-color-pink-accent mdui-m-a-1">show-second</button>
</div>
<script src="https://cdn.w3cbus.com/library/mdui/1.0.2/js/mdui.min.js"></script>
</body>
</html>
JavaScript
var $ = mdui.$;
var inst = new mdui.Tab('#tab');
// method
$('#prev').on('click', function () {
inst.prev();
});
$('#next').on('click', function () {
inst.next();
});
$('#show-first').on('click', function () {
inst.show(0);
});
$('#show-second').on('click', function () {
inst.show('tab2');
});
// event
$('#tab').on('change.mdui.tab', function (event) {
console.log('event: change; tab: ' + event._detail.index);
});
$('#tab1').on('show.mdui.tab', function () {
console.log('event: show; tab: 0');
});
$('#tab2').on('show.mdui.tab', function () {
console.log('event: show; tab 1');
});
$('#tab3').on('show.mdui.tab', function () {
console.log('event: show; tab 2');
});