循环遍历特定对象和特定属性
我正在编写一个 jQuery 验证插件,并希望循环访问某些对象并访问某些属性。我将一些规则设置为插件的属性,如下所示:
num:
{
msg: 'numbers only', //error messege
rule: /\bnum\b/, //regex to find if the rule is set
regex: /[^0-9]/ //regex for validating the field
}
在我的主要函数中,我试图验证规则组。其中一组是使用 1 个正则表达式的规则。我尝试将它们放入数组中
var group=(num, alpha)
,但从这里我无法弄清楚如何以一种可以访问对象属性的方式循环它们。
I'm writing a jQuery validation plugin and would like to loop through some of the objects and access certain properties. I have some of the rules set as a property of the plugin like so:
num:
{
msg: 'numbers only', //error messege
rule: /\bnum\b/, //regex to find if the rule is set
regex: /[^0-9]/ //regex for validating the field
}
In my main function I'm am trying to validate groups of rules. One such group is rules that use 1 regular expression. I tried putting them into arrays
var group=(num, alpha)
But from here I couldn't figure out how to loop through them In a way I can access the objects properties.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要访问对象的属性:
To access an object's properties: