Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/477.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
Javascript jQuery验证插件:在表的下一列(td)中显示错误消息/图像_Javascript_Jquery_Forms_Jquery Plugins_Validation - Fatal编程技术网

Javascript jQuery验证插件:在表的下一列(td)中显示错误消息/图像

Javascript jQuery验证插件:在表的下一列(td)中显示错误消息/图像,javascript,jquery,forms,jquery-plugins,validation,Javascript,Jquery,Forms,Jquery Plugins,Validation,我正在使用jquery验证插件和zend框架。我把表格放在桌子上。当文本字段未验证时,我将图像显示为错误。错误图像显示在同一td表的文本框旁边。但我想在同一tr的下一个td中显示错误消息/图像 例如,在提交之前: <table><tr><td>First Name</td><td><input type="text" class="required" /></td><td></td><

我正在使用jquery验证插件和zend框架。我把表格放在桌子上。当文本字段未验证时,我将图像显示为错误。错误图像显示在同一td表的文本框旁边。但我想在同一tr的下一个td中显示错误消息/图像

例如,在提交之前:

<table><tr><td>First Name</td><td><input type="text" class="required" /></td><td></td></tr></table>
名字
我希望在提交后使用空字段:

<table><tr><td>First Name</td><td><input type="text" class="required" /></td><td><img id='exclamation' src='images/exclamation.gif' title='This field is required.' /></td></tr></table>
名字
我现在正在使用这个js函数:

$(obj).find("input.required").each(function(){
      $(this).rules("add", {
            required: true,
            minlength: 2,

            messages: {

                    required : "<img id='exclamation' src='images/exclamation.gif' title='This field is required.' />",
                    minlength: "<img id='exclamation' src='images/exclamation.gif' title='At least 2 characters.' />"

            }
      });
});
$(obj).find(“input.required”).each(函数(){
$(此).rules(“添加”{
要求:正确,
最小长度:2,
信息:{
必填项:“”,
minlength:“
}
});
});

过了一会儿,我得到了答案。事实上,我想在输入字段的下一列(td)中显示一个带有标注(包含错误)的图像,该标注未经验证插件验证。当验证输入字段时,应删除此错误图像及其标注

这是我的解决办法

$("form").validate({

    errorPlacement: function(error, element) {

        //There should be an error
        if(error.html() != ''){         

            element.parent().next().html("<img id='exclamation' src='images/exclamation.gif' />").callout({
                width       : 200,
                cornerRadius    : 8,
                className   : "validationCallout",
                content     : error,
                align       : "left",
                nudgeHorizontal : -14,
                nudgeVertical   : 4,
                arrowHeight : 6
            });     
        }
    },

    success: function( label ) {
        $(obj).find(".valid").parent().next().html("");         //remove error image from next column(td) of input containing "valid" class
        $(obj).find(".valid").parent().next().closeCallout();   //remove callout on error image from next column(td) of input containing "valid" class
    }

});
$(“表单”)。验证({
errorPlacement:函数(错误,元素){
//应该有一个错误
如果(error.html()!=“”){
element.parent().next().html(“”).callout({
宽度:200,
转弯半径:8,
类名:“validationCallout”,
内容:错误,
对齐:“左”,
水平轻推:-14,
轻推垂直:4,
箭头高度:6
});     
}
},
成功:功能(标签){
$(obj).find(“.valid”).parent().next().html(“”;//从包含“valid”类的输入的下一列(td)中删除错误图像
$(obj).find(“.valid”).parent().next().closeCallout();//从包含“valid”类的输入的下一列(td)中删除错误图像上的标注
}
});
这段代码可能很复杂,但它现在正在为我工作。此处使用的标注插件与问题无关,但可能会帮助其他人。 有人能让它变得更简单吗