代码有几个问题:
-
你错过了
mdc-text-field__input
在文本字段中的输入元素上初始化,如
documentation
-
你有一个
text-field--outlined
在输入元素上初始化,但这很可能不会执行任何操作。如果要使用概述的变量,也可以在
documentation
. 请注意,它比填充(框)变量具有更多的标记。
-
我也建议不要使用
mdc-card__actions
你使用它的方式,因为它真正的目的是在一张卡的底部使用(每张卡使用一次)。
对于filled(box)变量,下面是一个有效的标记示例:
<div class="mdc-card">
<div>
<div class="mdc-text-field mdc-text-field--box username">
<input class="mdc-text-field__input" type="text" id="username-input" name="username" required>
<label class="mdc-floating-label" for="username-input">Email</label>
<div class="mdc-line-ripple"></div>
</div>
</div>
<div>
<div class="mdc-text-field mdc-text-field--box password">
<input class="mdc-text-field__input" type="password" id="password-input" name="password" required minlength="8">
<label class="mdc-floating-label" for="password-input">Password</label>
<div class="mdc-line-ripple"></div>
</div>
</div>
</div>
[].forEach.call(document.querySelectorAll('.mdc-text-field'), function(el) {
mdc.textField.MDCTextField.attachTo(el);
});