2015-04-01 151 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 2015-04-01 09:20:38

回答

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