检测动态table的行数,可判断非空

来源:互联网 发布:安大略理工大学知乎 编辑:程序博客网 时间:2024/06/07 07:01


<script type="text/javascript">
<!--检测这种动态的table有没有值,可以这样-->
  function checkRequired(){ 
    var rowLength=$("#contentLength").find("tbody").find("tr").length;//注意,这里没有(),因为length是属性,不是方法。

   //如果是空的,添加校验
    if(rowLength=="0"){
       alert("请最少添加一条详细信息");
      }
  }
     
</script>

<table id="myTable">
 <thead>
  <tr>
   <th>姓名</th>
   <th>年龄</th>
   <th>班级</th>
  </tr>
 <thead>
 <tbody>
  <tr>
   <td><a href="javescript;" onclick="addRow();"></td>
  </tr>
 </tbody>
</table>


原创粉丝点击