HTML
CSS
JavaScript
HTML
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>Tab 选项卡 - 通过 JavaScript 调用</title>
  <link rel="stylesheet" href="../assets/mdui-v0.2.1/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="../assets/mdui-v0.2.1/js/mdui.min.js"></script>
</body>
</html>
CSS

    
JavaScript
var inst = new mdui.Tab('#tab');

// method

document.getElementById('prev').addEventListener('click', function () {
  inst.prev();
});

document.getElementById('next').addEventListener('click', function () {
  inst.next();
});

document.getElementById('show-first').addEventListener('click', function () {
  inst.show(0);
});

document.getElementById('show-second').addEventListener('click', function () {
  inst.show('tab2');
});

// event

document.getElementById('tab').addEventListener('change.mdui.tab', function (event) {
  console.log('event: change; tab: ' + event.detail.index);
});

document.getElementById('tab1').addEventListener('show.mdui.tab', function () {
  console.log('event: show; tab: 0');
});

document.getElementById('tab2').addEventListener('show.mdui.tab', function () {
  console.log('event: show; tab 1');
});

document.getElementById('tab3').addEventListener('show.mdui.tab', function () {
  console.log('event: show; tab 2');
});