[英]jquery validate plugin
In my case name and id's of form are different and names are of format data[password] so thsi is the solution that i found on net and it works 在我的情况下,名称和ID的形式不同,名称的格式为data [password],所以这是我在网上找到的解决方案,它可以工作
$(document).ready(function()
{
var passwd = $("#old-password").attr("name");
var $params = {debug:false, rules:{}, messages:{}};
$params['rules'][passwd] = {"required": true, "maxlength": 100};
$params['messages'][passwd] = {"required": "Please Enter Old Password ",'maxlength':'Old Password should not exceed 100 characters'};
$("#GamerAccountSettingsForm").validate($params);
});
This outputs a label with class error but this is what i want it to do. 这会输出带有类错误的标签,但这是我想要的。 If there is a div with class error-message next to this input field it should show error inside it else it needs to append a div with class error-message to the input field 如果在此输入字段旁边有一个带有错误消息类的div,它应该在其中显示错误,否则需要在输入字段后面附加一个带有错误消息类的div。
You can use the errorPlacement options for this http://docs.jquery.com/Plugins/Validation/validate#options 您可以为此http://docs.jquery.com/Plugins/Validation/validate#options使用errorPlacement选项
And if I am correct, this should work; 如果我是正确的,那应该行得通;
$params['errorPlacement'] = function(error, element)
{
if($(element).next("div.error-message"))
{
$(element).next("div.error-message").html(error.html());
}
else
{
divError = $("<div class='error-message'>" + error.html() + "</div>");
divError.insertAfter(element);
}
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.