2011-11-11 1 views
1

jqueryバリデーションプラグインを使用しています(これはかなり新しいものです)、ラベルの隣に別のカスタムイメージと共に表示する必要がありますフィールドが誤っている場合。jqueryバリデーションプラグインを使用してエラーにエラーメッセージとカスタムイメージを追加する方法

messages: { 
    fname: "Enter your firstname", 
     lname: "Enter your lastname" 
}, 
errorPlacement: function(error, element) { 
     error.appendTo(element.parent("td").next()); 

}, 

がどのように私は、テキストと画像を追加するコードを追加します:

これは私が現在している何ですか?ここ

答えて

0

example

そして、それらの例えばコード

// extend the current rules with new groovy ones 

    // this one requires the text "buga", we define a default message, too 
    $.validator.addMethod("buga", function(value) { 
     return value == "buga"; 
    }, 'Please enter "buga"!'); 

    // this one requires the value to be the same as the first parameter 
    $.validator.methods.equal = function(value, element, param) { 
     return value == param; 
    }; 

    $().ready(function() { 
     var validator = $("#texttests").bind("invalid-form.validate", function() { 
      $("#summary").html("Your form contains " + validator.numberOfInvalids() + " errors, see details below."); 
     }).validate({ 
      debug: true, 
      errorElement: "em", 
      errorContainer: $("#warning, #summary"), 
      errorPlacement: function(error, element) { 
       error.appendTo(element.parent("td").next("td")); 
      }, 
      success: function(label) { 
       label.text("ok!").addClass("success"); 
      }, 
      rules: { 
       number: { 
        required:true, 
        minlength:3, 
        maxlength:15, 
        number:true 
       }, 
       secret: "buga", 
       math: { 
        equal: 11 
       } 
      } 
     }); 

    }); 

また、上記の例ではCSS

em.error { 
    background: url("images/unchecked.gif") no-repeat 0px 0px; 
    padding-left: 16px; 
} 
+0

の一部である、画像、テキストと組み合わされ..イメージとテキストの両方を別々に追加するものが必要です。フィールドの下のボックスに表示するテキストと、フィールドのラベルの横に表示するイメージが必要です。 – Ummul

+0

また、フィールドに正しい値を入力すると、画像とテキストが消える必要があります – Ummul

関連する問題