2015-04-01 4 views
-10
<script type="text/javascript"> 

    jQuery(function(){ 

     jQuery("#agree").validate({ 
      expression: "if (!isChecked(SelfID)) return false; else return true;", 
      message: "Please agree the terms and conditions" 
     }); 
    }); 

</script> 

<form> 
<input type="checkbox" value="agree" name="agree" id="agree" /> 
<input type="submit"> 
</form> 
+0

Что означает «не работает» в данном случае? (Мы обычно спрашиваем, что вопросы приводятся с подробным объяснением, помимо краткого описания в названии). – halfer

ответ

2

Вам нужно добавить проверку в виде элемента и установить необходимое правило флажком

<form id="myform"> 
    <input type="checkbox" value="agree" name="agree" id="agree" /> 
    <input type="submit"> 
</form> 

затем

jQuery(function ($) { 
    $("#myform").validate({ 
     rules: { 
      agree: { 
       required: true 
      } 
     }, 
     messages: { 
      agree: "Please agree the terms and conditions" 
     } 
    }); 
}); 

Демо: Fiddle

Смежные вопросы