2010-11-24 17 views
2

我正在使用jquery validation plugin。我只想在選中複選框時將5的minLength屬性設置爲字段。我理解的「依賴」,但我怎麼用5只有使用jquery驗證插件檢查複選框時纔將minLength設置爲字段

"txt-alt-zip": { 
      required: {                // the zip is required if the alternate billing address is checked 
       depends: function (element) { 
        return $("#chk-alt-billing-address").attr("checked"); 
       } 

      }, 
      minlength: {                // the zip is required if the alternate billing address is checked 
       depends: function (element) { 
        return $("#chk-alt-billing-address").attr("checked"); 
       } 

      } 

     } 

回答

1

從您的要求的值用它一起,這讓我更有意義:

"txt-alt-zip": { 
    minlength: function() { 
    $result = 0; 
    if ($("#chk-alt-billing-address").attr("checked")) $result = 4; 
    return $result; 
    } 
} 
4

在這裏你去

'txt-alt-zip': { 
    minlength: { 
    param: 4, 
    depends: '#chk-alt-billing-address:checked' 
    } 
} 

請注意,您可以使用任何類型的驗證規則。

相關問題