-1

showErrorsフォームの上部にエラー メッセージを表示するために jquery フォーム検証を使用しています。一度に 1 つのエラー メッセージを表示します。私のフォームでは、name,email,url and comment4 つのフィールドが利用可能です。ユーザーがデータを入力せずに送信ボタンを直接クリックすると、nameフィールドのエラーが表示されますが、ユーザーがフィールドにフォーカスすると、両方emailのエラーメッセージが上書きされます。nameemail

Jクエリ:-

$(document).ready(function(){
    $("form").validate({
    messages: {
         name: "Please specify your name.",
         email: {
           required: "We need your email address to contact you.",
           email: "Your email address must be in the format of name@domain.com."
         },
         url: "A valid URL, please.",
         comment: "Please enter your comment."
       },
    showErrors: function(errorMap, errorList) {
            if(errorList.length) {
                $("span").html(errorList[0].message);
            }
        }
    });
});

ここにフィドルがあります:- http://jsfiddle.net/roop1886/q64VE/

4

1 に答える 1

0

解決策:- focusInvalid: false,@Barmarによって提案された$("form").validate()機能を追加しました。

$(document).ready(function(){
    $("form").validate({
   focusInvalid: false,
    messages: {
         name: "Please specify your name.",
         email: {
           required: "We need your email address to contact you.",
           email: "Your email address must be in the format of name@domain.com."
         },
         url: "A valid URL, please.",
         comment: "Please enter your comment."
       },
    showErrors: function(errorMap, errorList) {
            if(errorList.length) {
                $("span").html(errorList[0].message);
            }
        }
    });
});
于 2013-06-12T06:14:39.617 に答える