检查成功和错误颜色的初始加载变化的形状

这是我的形式,我希望表单在发生错误时更改颜色/有事情发生。

例如,如果用户在强制性字段中没有输入任何内容,

我希望它使用类来改变颜色 bootstrap css, 有人能教我怎么做吗?

p. S.I-Nevice,对新手的问题感到遗憾。


<form class="form-horizontal">
<fieldset>
<!-- Form Name -->
<legend>Form Name</legend>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="name">Name</label>
<div class="col-md-5">
<input class="form-control input-md" id="name" name="name" placeholder="Enter Name" required="" type="text"/>
</div>
</div>
<!-- Password input-->
<div class="form-group">
<label class="col-md-4 control-label" for="password">Password</label>
<div class="col-md-5">
<input class="form-control input-md" id="password" name="password" placeholder="Enter Password" required="" type="password"/>
</div>
</div>
<!-- Button -->
<div class="form-group">
<label class="col-md-4 control-label" for="button"></label>
<div class="col-md-4">
<input class="btn btn-success" id="button" name="button" type="submit" value="Submit"/>
</div>
</div>
</fieldset>
</form>
已邀请:

二哥

赞同来自:

为此目的有一个选择器。 CSS /
:invalid

/, 但是在一个个人的入口水平。 例如,您可以通过检查无效的儿童的存在来绘制整个表单,例如:


/* add space to denote child element */
form :invalid {
background: red;
}

快网

赞同来自:

要下载,只需添加一个类
has-error

, 形成群体。


<div class="form-group has-error">
<label class="col-md-4 control-label" for="name">Name</label>
<div class="col-md-5">
<input class="form-control input-md" id="name" name="name" placeholder="Enter Name" required="" type="text"/>
</div>
</div>


有关更多信息,请参阅文档:
http://getbootstrap.com/css/#forms-help-text
和现场演示:
http://jsbin.com/daxocivoho/1/edit?html,output

要回复问题请先登录注册