jQuery隐藏功能无法正常工作

时间:2013-03-11 12:07:28

标签: jquery

这是我的PHP代码。在这里我创建一个表并通过从数据库中提取数据来填充数据。我正在打印两行。在第二个表格行中,我写了“Hello There”。我对.hide()函数的理解让我相信它应该隐藏在页面显示上。但它没有发生呢?

<table>
    <thead>
        <tr>
            <th>All Courses</th>
            <th>Center</th>
            <th>Batch</th>
            <th>Click for Info</th>
        </tr>
    </thead>
    <tbody>
              <?php 
                if($batch_query != null){
                  $i = 0;  
                  foreach($batch_query->result_array() as $row){
                    $val = "'".$row['course_id'].",".$row['center_id'].",".$row['batch_id']."'";
                    echo "<tr>";
                      echo "<td>".$row['course_name']."</td>";
                      echo "<td>"."<button id= \"btn_number_$i\"  class='btn info toggler' >Info   <i class='icon-arrow-down'></i></button>"."</td>";
                    echo "</tr>";
                    echo "<tr class='info_row'>Hello There!!</tr>";
                    $i++;
                  }
               }

在代码中我创建了两行,最初我想通过使用jQuery hide方法将第二行的display属性设置为none。

这是我在同一页面上的脚本标记之间的jQuery代码:

   $(function(){
    console.log('Hello World!!');// Just to test whether the code is being reached or not.  
    $('.info_row').hide();  
   });

但是这个hide()函数似乎不起作用。整个字符串“Hello there”仍保留在页面上。

这可能是什么原因?

2 个答案:

答案 0 :(得分:1)

试试这个

$(".tableClass table tr").eq(1).hide();

您需要<td>

中有<tr>

答案 1 :(得分:1)

你的html无效.. <td>

中的<tr>

应该是

 echo "<tr class='info_row'><td>Hello There!!</td></tr>";
                         //--^^-here 
相关问题