Materialise 创建并打开模态

Materialize Create and Open Modal

我不想使用 Materialize 创建模态框并通过单击按钮打开它。我使用了模态页面中的代码,但不知何故无法正常工作。也许有人可以提供帮助。

我知道有些人发布了类似的问题,但其中 none 正在回答我的问题。

对于使用按钮触发模式的模态示例,您需要使用 JavaScript 初始化按钮。请确保您已包含 jQuery,以及来自 materialize 的 JavaScript 和 CSS — 请参阅 getting started guide.

要初始化模态(或所有模态),您将对其调用 leanModal() 方法:

$(document).ready(function(){
  $('.modal-trigger').leanModal();
});

The "href" attribute of .modal-trigger must specify the modal ID that wants to be triggered.

模态按钮示例:

<a class="waves-effect waves-light btn modal-trigger" href="#modal1">Click to open modal</a>

此按钮将打开 ID 为 modal1 的模式。

请参阅此 code pen 以获取工作示例。