我使用MaterialiseCSS显示电子邮件表单,当电子邮件验证失败时,我想隐藏一个"线索"元件。
.input-field .clue {
color: #666;
font-family: 'Nothing You Could Do', cursive;
margin-top:-0.8rem;
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/jquery.validation/1.14.0/jquery.validate.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.1/css/materialize.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.1/js/materialize.min.js"></script>
<form id="testForm">
<div class="input-field">
<input id="email" type="email" class="validate" required="" aria-required="true">
<label for="email" data-error="wrong email adress" data-success="right">Email</label>
<p id="clue-email" class="clue">We don't spam, never !</p>
</div>
</form>
&#13;
如果您尝试输入&#34; test&#34;作为电子邮件地址,警告消息和线索消息是混合的。当警告消息出现时(#34;错误的电子邮件地址&#34;)
我想隐藏线索消息(&#34;我们不会垃圾邮件,永远不会!&#34;)我不知道我是应该在纯CSS还是在Jquery中这样做。
感谢您的帮助,
此致
阿克塞尔
答案 0 :(得分:3)
由于input
获得invalid
或valid
类,您可以添加以下CSS规则,该规则会隐藏位于{{1}之后的hide-on-input-message
类的所有项目在同一input
:
input-field
更新了代码段:
.input-field input.invalid ~ .hide-on-input-message,
.input-field input.valid ~ .hide-on-input-message
{
display: none;
}
&#13;
.input-field .clue {
color: #666;
font-family: 'Nothing You Could Do', cursive;
margin-top:-0.8rem;
}
.input-field input.invalid ~ .hide-on-input-message, .input-field input.valid ~ .hide-on-input-message {
display: none;
}
&#13;