jQuery验证字段的名称属性包含方括号? [英] jQuery Validate field where Name attribute contains square brackets?
本文介绍了jQuery验证字段的名称属性包含方括号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图验证一个包含带有方括号[]的名称属性的字段的表单。这是一个要求,我不能改变名称属性为别的东西,它只是似乎混乱尝试通过ID或ClassName验证..
我将如何去验证如下例所示?到目前为止它不起作用(由于出错导致我的整个页面完全消失。)
$(#loginForm) .validate({
规则:{
登录[用户名]:{
required:true,
email:true
}
} ,
信息:{
登录[用户名]:{
required:请提供电子邮件,
电子邮件:请输入一个有效的电子邮件地址
}
}
});
解决方案在JavaScript对象中使用
login [用户名]
是无效的语法,请使用引号使其有效login [username ]
I am attempting to validate a form that contains fields with name attributes containing square brackets []. It's a requirement that I cannot change the name attribute to something else, and it just seems messy trying to validate via ID or ClassName..
How would I go about validating the w as the following example? As of now it does not work (makes my entire page completely dissappear due to an error.
$("#loginForm").validate({
rules: {
login[username]: {
required: true,
email: true
}
},
messages: {
login[username]: {
required: "Please provide an email",
email: "Please enter a valid email address"
}
}
});
解决方案
using login[username]
inside a javascript object is not valid syntax. Use quotes around it to make it valid "login[username]"
这篇关于jQuery验证字段的名称属性包含方括号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文