我使用此表格
<div class="row">
<form class="col s12">
<div class="row">
<div class="input-field col s12">
<input id="email2" type="email" class="validate">
<label for="email2" data-error="wrong" data-success="right">Email</label>
</div>
<div class="input-field col s12">
<input id="example" name="example" type="text" class="validate" required="" aria-required="true">
<label for="example" data-error="wrong" data-success="right">Field</label>
</div>
</div>
</form>
</div>
邮件字段没问题。如果我在错误的邮件地址中发布错误消息。
示例字段不起作用。我会检查字段是否为空,然后显示错误。
出了什么问题?
答案 0 :(得分:14)
您忘记添加required=""
和aria-required="true"
这是完整的片段:
<div class="row">
<form class="col s12">
<div class="row">
<div class="input-field col s12">
<input id="email2" type="email" class="validate" required="" aria-required="true">
<label for="email2" data-error="wrong" data-success="right">Email</label>
</div>
<div class="input-field col s12">
<input id="example" name="example" type="text" class="validate" required="" aria-required="true">
<label for="example" data-error="wrong" data-success="right">Field</label>
</div>
<div class="input-field col s12">
<button class="btn waves-effect waves-light" type="submit" name="action">Submit</button>
</div>
</div>
</form>
</div>
答案 1 :(得分:1)
评论 ichadhr&#39> 评论
/ **错误消息的FIXES * /
label {
width: 100%;
}
.input-field label:not(.active):after {
font-size: 0.8rem;
-webkit-transform: translateY(-140%);
-moz-transform: translateY(-140%);
-ms-transform: translateY(-140%);
-o-transform: translateY(-140%);
transform: translateY(-140%);
}