【发布时间】:2013-07-25 12:43:03
【问题描述】:
我使用 Twitter Bootstrap 框架创建了一个表单并集成了 jQuery 验证插件。我有一个表单,其中包含一系列带有单选按钮的是/否问题,我验证这些单选按钮以确保每个问题都不为空 - 这很好用。
我想利用 Bootstrap class="control-group error" 使错误文本显示为红色,以便用户能够看到 - 目前“此字段为必填项”文本为黑色,很难定位。
这里有一个我希望错误文本如何显示的示例:
http://twitter.github.io/bootstrap/base-css.html#forms
在本节末尾的“验证状态”下。这是在输入字段后显示红色消息的具体示例(我只希望在他们单击提交按钮后出现错误):
<div class="control-group error">
<label class="control-label" for="inputError">Input with error</label>
<div class="controls">
<input type="text" id="inputError">
<span class="help-inline">Please correct the error</span>
</div>
</div>
这是我的表格,显示了一个问题:
<form class="form-horizontal" method="post" id="inputForm">
<input type="hidden" name="recid" value="1">
<table class="table table-condensed table-hover table-bordered">
<h2>Input Form</h2>
<tr>
<td>Question 1.</td>
<td>
<div class="controls">
<label class="radio inline">
<input type="radio" name="q1" value="Yes" required>Yes </label>
<label class="radio inline">
<input type="radio" name="q1" value="No" required>No </label>
<label for="q1" class="error"></label>
</div>
</td>
<td>Please answer Yes or No</td>
</tr>
</table>
</div>
<div class="control-group">
<div class="controls">
<button type="submit" class="btn btn-primary">Continue</button>
<button type="reset" class="btn">Reset</button>
</div>
</div>
</form>
我不知道如何将示例与我的表单结合起来,这样如果他们提交了表单并且他们没有回答问题,则警报会显示为红色。
我已经设置了一个 jsFiddle here,如果有帮助,它会显示这是行动。
【问题讨论】:
-
这是一个关于 jQuery Validate 的问题...所以展示你的 jQuery/JavaScript。
-
顺便说一句,
class="control-group error"实际上包含 两个 类,.control-group和.error。
标签: twitter-bootstrap jquery-validate