2009-10-28 32 views
0

我的代碼是:jQuery.validator.methods.required()

$.validator.addMethod("dateBR", function dateBR(value, element) { 

    return /^(?:(?:(?:0?[1-9]|1\d|2[0-8])\/(?:0?[1-9]|1[0-2]))\/(?:(?:1[6-9]|[2-9]\d)\d{2}))$|^(?:(?:(?:31\/0?[13578]|1[02])|(?:(?:29|30)\/(?:0?[1,3-9]|1[0-2])))\/(?:(?:1[6-9]|[2-9]\d)\d{2}))$|^(?:29\/0?2\/(?:(?:(?:1[6-9]|[2-9]\d)(?:0[48]|[2468][048]|[13579][26]))))$/.test(value); 
} 

,但我要檢查它只有在需要的元素... 我該怎麼辦呢?

10X !!

回答

0

添加一類的 '要求' 到你的元素:

<input class='required' /> 

然後通過與類名的循環:

$(this).attr('class').split(' ');