1

这是我在其中渲染表格行的 PHP 代码块:-

实际上,我想要实现的是,在单击第一行中的按钮时,我应该能够显示下一行,该行以前通过在文档就绪脚本中使用 .hide() 隐藏。

     <?php
         echo "<tr>";
            echo "<td>"."<button id= \"btnnumber_". $i ." \"  class=\"btn info toggler\" data-value=\" $val\">Show Info  <i class=\"icon-arrow-down\"></i></button>"."</td>"; // On click of this button I am taking its id in Jquery getting the number at end creating the id of the next row in the Jquery script.
         echo "</tr>";

         echo "</tr>";
            echo "<tr id=\"row_$i \" class=\"info_row\">";// This row is dynamically generated one each row has its unique id like 0 row is having id row_0,1 row is having id row_1 etc.
            echo "<td id=\"student_count\">"."students count:"."</td>";
            echo "<td id=\"start_date\">"."start date: "."</td>";
            echo "<td id =\"end_date\">"."end date: "."</td>";
            echo "<td></td>";
        echo "</tr>";

 ?>

该行最初设置为使用以下 JQuery 隐藏在准备好的文档中:-

          $(function(){

              $('.info_row').hide();// On document load I am hiding all the element with class info_row.


              $('.toggler').toggle(function(){// Then I am toggling between hide and show.

               var currentId = $(this).attr('id');
               var number = currentId.substr(currentId.length - (currentId.length - currentId.indexOf("_") - 1));
               var rowId = 'row_' + number;
               $("#" + rowId).show();
             }, function(){

              var currentId = $(this).attr('id');
              var lastChar = currentId.substr(currentId.length - (currentId.length - currentId.indexOf("_") - 1));
              var rowId = 'row_' + lastChar; 
              $("#" + rowId).hide();

      });  
    });

我无法实现切换,即行没有像我试图实现的那样隐藏和显示。

任何帮助将不胜感激。

4

1 回答 1

3

这条线看起来有问题

 echo "<tr id=\"row_$i \" 

因为在 id 中有一个虚假的空间。

echo "<tr id=\"row_$i\" 
于 2013-03-14T06:36:24.207 回答