HTML
CSS
JavaScript
play_arrow
HTML
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>对话框 - 通过 JavaScript 调用</title>
  <link rel="stylesheet" href="//cdn.jsdelivr.net/npm/mdui@1.0.1/dist/css/mdui.min.css"/>
</head>
<body class="mdui-theme-primary-indigo mdui-theme-accent-pink">

<div class="mdui-container">

  <div class="mdui-dialog" id="dialog">
    <div class="mdui-dialog-title">Are you sure?</div>
    <div class="mdui-dialog-content">You'll lose all photos and media!</div>
    <div class="mdui-dialog-actions">
      <button class="mdui-btn mdui-ripple" mdui-dialog-cancel>cancel</button>
      <button class="mdui-btn mdui-ripple" mdui-dialog-confirm>erase</button>
    </div>
  </div>

  <button id="open" class="mdui-btn mdui-color-pink-accent">open</button>

</div>

<script src="//cdn.jsdelivr.net/npm/mdui@1.0.1/dist/js/mdui.min.js"></script>
</body>
</html>
CSS

  
JavaScript
var inst = new mdui.Dialog('#dialog');

// method
document.getElementById('open').addEventListener('click', function () {
  inst.open();
});


// event
var dialog = document.getElementById('dialog');

dialog.addEventListener('open.mdui.dialog', function () {
  console.log('open');
});

dialog.addEventListener('opened.mdui.dialog', function () {
  console.log('opened');
});

dialog.addEventListener('close.mdui.dialog', function () {
  console.log('close');
});

dialog.addEventListener('closed.mdui.dialog', function () {
  console.log('closed');
});

dialog.addEventListener('cancel.mdui.dialog', function () {
  console.log('cancel');
});

dialog.addEventListener('confirm.mdui.dialog', function () {
  console.log('confirm');
});