2011-10-13 56 views
2
$("#myform").validate({ 
     submitHandler: function (form) { 
      var cboxes = ($('input:checkbox:checked').filter(":checked").length); 
      var nboxes = ($(":checkbox:not(:checked)").length); 
      var flag = false; 
      if ((cboxes > 0) && (nboxes > 0)) { 
       flag = confirm('You have Checked only few locations among the List. \n Are you sure, you do not want to Prescribe from the other locations? '); 
      } else if (cboxes == 0) { 
       alert('Please select atleast One Address \n Where you would prefer to prescribe from.'); 
      } 
      else { 
       flag = true; 
      } 
      return flag; 
     } 
    }); 

當確認框彈出,如果我點擊確定它應接受提交,但事實並非如此。的JavaScript Submithandler問題

誰能告訴我爲什麼會發生這種情況?

回答

2

return flag替換爲form.submit

$("#myform").validate({ 
    submitHandler: function (form) { 
     var cboxes = ($('input:checkbox:checked').filter(":checked").length); 
     var nboxes = ($(":checkbox:not(:checked)").length); 
     var flag = false; 
     if ((cboxes > 0) && (nboxes > 0)) { 
      flag = confirm('You have Checked only few locations among the List. \n Are you sure, you do not want to Prescribe from the other locations? '); 
     } else if (cboxes == 0) { 
      alert('Please select atleast One Address \n Where you would prefer to prescribe from.'); 
     } 
     else { 
      flag = true; 
     } 

     if(flag) 
      form.submit(); 
    } 
}); 

如果您不使用AJAX,這是在.validate() docs中描述的方式。

+0

謝謝你的工作 – HaBo