2011-08-22 75 views
0

工作我使用jQuery驗證插件(http://bassistance.de/jquery-plugins/jquery-plugin-validation/)規則不進行驗證

下面的代碼形式的一部分

<input type="checkbox" name="a_r[]" value="one" id="ar_one" />Visitors 
<input type="checkbox" name="a_r[]" value="two" id="ar_two" />Actions 
<input type="checkbox" name="a_r[]" value="three" id="ar_three" />Referrers 

我需要檢查是否有2個複選框被選中與否,只有在特定的無線電值設置爲「Y」

<input type="radio" name="allowusage" id="allowusage" value="n" checked />No&nbsp;&nbsp;&nbsp;&nbsp; 
<input type="radio" name="allowusage" id="allowusage" value="y" />Yes 

我已經寫了下面的規則,但它不工作的一些方式。

a_r:{required:function() {return jQuery('input[name|="allowusage"]:checked').val() == 'y';},minlength:2}, 

基本上,我需要排除這樣

如果allowusage值是 'Y',則需要選擇複選框,否則不是。 並且如果allowusage值是「Y」則至少2個複選框需要選擇

回答

0

規則應該像

"a_r[]":{required:function() {return jQuery('input[name|="allowusage"]:checked').val() == 'y';},minlength:2},