jquery验证多选择框

时间:2016-10-10 14:15:32

标签: jquery validation

我有一个包含多个选择列表框的表单。 我在这里使用它(https://silviomoreto.github.io/bootstrap-select/examples/#custom-button-text) 我想验证它。每件事情都很好,当我点击提交表单时,它会返回一条消息,说明此字段需要,但边框颜色不会变为红色。

2 个答案:

答案 0 :(得分:0)

<select required multiple>
  <option value="1">item1</option>
  <option value="2">item2</option>
</select>
<style>
 .has-error .btn-default{border:2px solid red !important}
</style>

答案 1 :(得分:0)

我创造了一个小提琴,我看不出问题。您可以查看此链接https://jsfiddle.net/36zopv3v/2/

<form data-toggle="validator" role="form">
  <div class="form-group">
    <label class="control-label">Select</label>
    <select required multiple class="form-control selectpicker">
      <option value="1">item1</option>
      <option value="2">item2</option>
    </select>
  </div>
  <div class="form-group">
    <label for="inputName" class="control-label">Name</label>
    <input type="text" class="form-control" id="inputName" placeholder="Cina Saffary" required>
  </div>
  <div class="form-group has-feedback">
    <label for="inputTwitter" class="control-label">Twitter</label>
    <div class="input-group">
      <span class="input-group-addon">@</span>
      <input type="text" pattern="^[_A-z0-9]{1,}$" maxlength="15" class="form-control" id="inputTwitter" placeholder="1000hz" required>
    </div>
    <span class="glyphicon form-control-feedback" aria-hidden="true"></span>
    <div class="help-block with-errors">Hey look, this one has feedback icons!</div>
  </div>
  <div class="form-group">
    <label for="inputEmail" class="control-label">Email</label>
    <input type="email" class="form-control" id="inputEmail" placeholder="Email" data-error="Bruh, that email address is invalid" required>
    <div class="help-block with-errors"></div>
  </div>
  <div class="form-group">
    <label for="inputPassword" class="control-label">Password</label>
    <div class="form-inline row">
      <div class="form-group col-sm-6">
        <input type="password" data-minlength="6" class="form-control" id="inputPassword" placeholder="Password" required>
        <div class="help-block">Minimum of 6 characters</div>
      </div>
      <div class="form-group col-sm-6">
        <input type="password" class="form-control" id="inputPasswordConfirm" data-match="#inputPassword" data-match-error="Whoops, these don't match" placeholder="Confirm" required>
        <div class="help-block with-errors"></div>
      </div>
    </div>
  </div>
  <div class="form-group">
    <div class="radio">
      <label>
        <input type="radio" name="underwear" required> Boxers
      </label>
    </div>
    <div class="radio">
      <label>
        <input type="radio" name="underwear" required> Briefs
      </label>
    </div>
  </div>
  <div class="form-group">
    <div class="checkbox">
      <label>
        <input type="checkbox" id="terms" data-error="Before you wreck yourself" required> Check yourself
      </label>
      <div class="help-block with-errors"></div>
    </div>
  </div>
  <div class="form-group">
    <button type="submit" class="btn btn-primary">Submit</button>
  </div>
</form>