HTML
CSS
JavaScript
HTML
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>通过 JavaScript 调用 - Select</title>
  <link rel="stylesheet" href="https://cdn.w3cbus.com/library/mdui/1.0.2/css/mdui.min.css"/>
</head>
<body>

  <div class="mdui-container">
    <button class="mdui-btn mdui-color-pink-accent" id="open">open</button>
    <button class="mdui-btn mdui-color-pink-accent" id="close">close</button>
    <button class="mdui-btn mdui-color-pink-accent" id="toggle">toggle</button>
    <button class="mdui-btn mdui-color-pink-accent" id="additem">添加一个选项</button>
  </div>
  <div class="mdui-container mdui-valign" style="height: 400px;">
    <select class="mdui-select" id="demo">
      <option value="1">State 1</option>
      <option value="2">State 2</option>
      <option value="3" disabled>State 3</option>
      <option value="4">State 4</option>
      <option value="5">State 5</option>
      <option value="6">State 6</option>
    </select>
  </div>

  <script src="https://cdn.w3cbus.com/library/mdui/1.0.2/js/mdui.min.js"></script>
</body>
</html>
CSS

  
JavaScript
var $ = mdui.$;
var inst = new mdui.Select('#demo');

// 方法
$('#open').on('click', function (e) {
  e.stopPropagation();
  inst.open();
});

$('#close').on('click', function (e) {
  e.stopPropagation();
  inst.close();
});

$('#toggle').on('click', function (e) {
  e.stopPropagation();
  inst.toggle();
});

$('#additem').on('click', function () {
  $('#demo').append('<option>new state</option>');
  inst.handleUpdate();
});

// 事件
$('#demo').on('open.mdui.select', function () {
  console.log('event open');
});

$('#demo').on('opened.mdui.select', function () {
  console.log('event opened');
});

$('#demo').on('close.mdui.select', function () {
  console.log('event close');
});

$('#demo').on('closed.mdui.select', function () {
  console.log('event closed');
});