Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用jquery验证插件将错误消息和自定义图像添加到错误字段_Jquery_Validation_Jquery Plugins - Fatal编程技术网

如何使用jquery验证插件将错误消息和自定义图像添加到错误字段

如何使用jquery验证插件将错误消息和自定义图像添加到错误字段,jquery,validation,jquery-plugins,Jquery,Validation,Jquery Plugins,我正在使用jquery验证插件(我对它还很陌生),如果字段出错,我需要在标签旁边显示错误消息和另一个自定义图像 这就是我目前拥有的: messages: { fname: "Enter your firstname", lname: "Enter your lastname" }, errorPlacement: function(error, element) { error.appendTo( element.parent("td").next())

我正在使用jquery验证插件(我对它还很陌生),如果字段出错,我需要在标签旁边显示错误消息和另一个自定义图像

这就是我目前拥有的:

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

},
如何添加代码以同时附加图像和文本?

以下是

以及这些示例的代码

// 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;
}

在上面的示例中,图像与文本组合。。我需要一些东西,分别添加图像和文本。。我需要文本显示在字段下方的框中,图像显示在字段标签旁边。此外,当我在字段中输入正确的值时,我需要图像和文本消失