如何使用jquery验证检查空数据表

如何使用jquery验证检查空数据表,jquery,datatables,jquery-validate,Jquery,Datatables,Jquery Validate,如果我的表为空,我希望验证我的表。我的表使用datatables添加数据 <form method="post" id="form"> <input type="text" id="txt" required> <table id="table"> <thead> <tr> <th>No.</th> <th>Name</th>

如果我的表为空,我希望验证我的表。我的表使用datatables添加数据

<form method="post" id="form">
  <input type="text" id="txt" required>
  <table id="table">
    <thead>
      <tr>
        <th>No.</th>
        <th>Name</th>
        <th>Address</th>
      </tr>
    </thead>
  </table>
<button id="button" type="submit">Save</button>
</form>
如果输入。我只是添加必需的属性。但是如果数据表为空,如何检查数据表。如果我没有添加一些项目。上表或上表中的返回消息错误


注意:这是如何检查datatables空表。数据。任何

都可以添加隐藏的虚拟输入元素。例如:

<input type="hidden" name="table_required">
<input type="hidden" name="table_required">
$("#form").validate({
   rules: {
      table_required: {
         required: function(){
            return $('#table').DataTable().data().any();
         }
      }
   },
   submitHandler: function (form) {
      form.submit();
   }
});