【发布时间】:2016-10-06 13:58:33
【问题描述】:
我的注册表单使用 HTML5 验证来验证必填字段是否已完成。
<div class="container">
<div class="row">
<div class="col-md-6 col-md-offset-3">
<form action="https://www.salesforce.com" method="POST" id="signup">
<div class="form-group">
<label for="first_name">First name</label>
<input id="first_name" maxlength="40" name="first_name" size="20" type="text" class="form-control" required>
</div>
<div class="checkbox">
<label>
<input id="tou" name="tou" type="checkbox" value="1" required="required"/>
I have read and agree to the terms of use.
</label>
</div>
<input type="submit" name="submit" class="btn">
</form>
</div>
</div>
</div>
我已使用 CSS 将默认复选框替换为自定义 .svg 复选框。
input[type=checkbox] {
display: inline-block;
font-style: normal;
font-weight: normal;
line-height: 1;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
visibility: hidden;
}
input[type=checkbox]:before {
content: url(/static/img/unchecked.svg);
visibility: visible;
}
input[type=checkbox]:checked:before {
content: url(/static/img/checked.svg);
}
虽然 HTML5 验证适用于其他字段,但我无法让它适用于自定义复选框。我尝试了jQuery validation with custom CSS checkbox中显示的方法,但没有成功。有什么想法吗?
【问题讨论】:
-
如果您在进行 jquery 验证时遇到问题,为什么要向我们展示 css?
-
是否有理由将 required 设置为属性?为什么不按照您在文本输入中设置所需的方式进行设置?
-
@AdamBuchananSmith 我想展示如何隐藏默认复选框,以防解决方案需要它。
-
@macksol 很好。没有理由将 required 设置为属性。
标签: css html forms checkbox twitter-bootstrap-3