5

フォーム内のすべての入力を検証するjQuery 検証プラグインを使用していますが、最初の入力で停止します。2番目の入力をクリックして空白のままにすると、すべて問題ありません-検証されます...
そうでない場合-そうではありません...

私はいくつかの同じ答えを見つけました - 成功しませんでした...

これが私が書いた例のフィドルです

FiddleError

//
//  jQuery Validate example script
//
//  Prepared by David Cochran
//
//  Free for your use -- No warranties, no guarantees!
//

$(document).ready(function(){

// Validate
// http://bassistance.de/jquery-plugins/jquery-plugin-validation/
// http://docs.jquery.com/Plugins/Validation/
// http://docs.jquery.com/Plugins/Validation/validate#toptions

    $('.validate').validate({
        highlight: function(element) {
            $(element).parent().removeClass('has-success').addClass('has-error');
        },
        success: function(element) {
            element.closest().removeClass('has-error').addClass('has-success');
        }
  });

}); // end document.ready`enter code here`

使用:

  • ブートストラップ
  • jQuery
  • jQuery の検証
4

2 に答える 2

17

name代わりにフィールドに使用しますid

<div class="form-group">
    <label class="control-label" for="login_id">Login id:</label>
    <input type="text" class="form-control required" name="login_id">
</div>
<div class="form-group">
    <label class="control-label" for="password">Password:</label>
    <input type="password" class="form-control required" name="password">
    <div class="forgot"> <a href="#">
                    Forgot your password?
                </a>

    </div>
</div>

デモ:フィドル

于 2013-09-24T16:56:15.193 に答える
-1

あなたのコードは、どのフィールドが必要かを .validate() に伝えていません。プラグインのドキュメントから: http://jqueryvalidation.org/required-method

フィールドを必須にするには:

$( "#myform" ).validate({
  rules: {
    fruit: {
      required: true
    }
  }
});

この場合、「果物」というフィールドが必要です。

于 2013-09-24T16:56:10.947 に答える