<table id="jobSkills">
<tr><th></th><th></th></tr>
<tr><td></td></tr> //i want to check this tr present or not.?
</table>


我有要检查第二个tr的表,我该怎么办?

if($("#jobSkills tr").length > 0){ //second tr
alert("working");
}else{
alert("not-working");
}


我可以对第一个tr进行验证,但是对第二个我感到困惑

最佳答案

检查长度是否大于1而不是0:


if($("#jobSkills tr").length > 1){ //second tr
  alert("working");
}else{
  alert("not-working");
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table id="jobSkills">
  <tr>
    <th></th>
    <th></th>
  </tr>
  <tr>
    <td></td>
  </tr>
</table>

07-24 09:50
查看更多