2015-03-13 110 views
0

当我点击第一行时,它显示输出。
当我点击秒,它也显示,但第一行不隐藏。
它仍在显示。如何在JavaScript中隐藏上一行?

它应该发生在所有的行上,而不仅仅是前两个。

JavaScript代码:

$('#table_struct tr').click(function() { 
    var $this = $(this); 
    var offset = $this.offset(); 
    var height = $this.height(); 
    var order_id = $this.data('order_id'); 
    $('.menu').remove(); 
    $.get('getuser.php?order_id=' + order_id, function(table) { 
     $('#showmenu').append(table); 
     $('.menu').css({ 
      right: offset.right, 
      top: offset.top+height 
     }); 
    }); 
}); 

的index.php

  include "db.php"; 
         $query = "select * from orders_list"; 
         $result = mysql_query($query); 

         $num_rows = mysql_num_rows($result); 
         if($num_rows >= 1) 
          { 

          echo "<div id='showmenu' class='scroll'>"; 
         echo "<table id='table_struct' cellspacing='0' cellpadding='1' border='1' width='400' height='30'> 
          <tr class='tr_class' bgcolor='white'> 
          <td align='center' style='font-weight:bold'> Select </td> 
          <td align='center' style='font-weight:bold'> order_id </td> 
          <td align='center' style='font-weight:bold'> customer_name </td> 
          <td align='center' style='font-weight:bold'> no_of_pack </td> 
          <td align='center' style='font-weight:bold'> price </td> 
          <td align='center' style='font-weight:bold'> Weight </td> 
          <td align='center' style='font-weight:bold'> payment mode </td> 



         </tr>"; 

          while($row = mysql_fetch_array($result)) 
          { 

            $order_id = $row['order_id']; 
            $_SESSION['order_id'] = $order_id; 
            echo "<tr height='20' data-order_id='".$row['order_id']."'> 
            <td align='center'><input type='checkbox' class='case' name='case' value='1'></td> 
            <td align='center'>".$row['order_id']."</td> 
            <td align='center'>".$row['customer_name']."</td> 
            <td align='center'>".$row['number_of_pack']."</td> 
            <td align='center'>".$row['price']."</td> 
            <td align='center'>".$row['weight']."</td> 
            <td align='center'>".$row['payment']."</td>"; 

          echo "</tr>"; 
            } 
            echo "</table>"; 
            echo "</div>"; 
            } 


        if(!mysql_close($con)) 
        { 
         echo "failed to close"; 
        } 

getuser.php

    include "db.php"; 
       $order_id = intval($_GET['order_id']); 
       $query = "select * from orders_details where order_id=$order_id"; 
         $result = mysql_query($query); 

         $num_rows = mysql_num_rows($result); 
         if($num_rows >= 1) 
          { 
          echo "<div class='menu' class='scroll'>"; 
         echo "<table id='table_struct' cellspacing='0' cellpadding='1' border='1' width='650' height='30'> 
          <tr class='tr_class' bgcolor='white'> 
          <td align='center' style='font-weight:bold'> Product </td> 
          <td align='center' style='font-weight:bold'> Quantity </td> 
          <td align='center' style='font-weight:bold'> Sku </td> 
          <td align='center' style='font-weight:bold'> Price </td> 
          <td align='center' style='font-weight:bold'> Total </td> 

         </tr>"; 

          while($row = mysql_fetch_array($result)) 
          { 
            echo "<tr height='30'> 
            <td align='center'>".$row['product']."</td> 
            <td align='center'>".$row['quantity']."</td> 
            <td align='center'>".$row['sku']."</td> 
            <td align='center'>".$row['price']."</td> 
            <td align='center'>".$row['total']."</td>"; 

          echo "</tr>"; 
            } 
            echo "</table>"; 
            echo "</div>"; 
            } 
+0

使用具有标识符的'jquery'的'hide'或'remove'功能。 – 2015-03-13 09:33:09

+0

使用最接近和隐藏jQuery的事件。如果可能的话, – 2015-03-13 09:35:37

+0

也提供html – 2015-03-13 09:40:05

回答

0

jQuery有以前的选择...也许你可以使用?从jQuery的文档页面采取 代码:$("li.third-item").prev().css("background-color", "red");

基本上你可以这样做:$('something').click(function() { $(this).prev().hide(); })$(this).parent().prev().hide();

0

我不能完全肯定PHP是如何工作的,但如果你正在对表进行dynamicaly由(您的JavaScript后已经运行),那么你的jQuery选择不工作..

$('#table_struct tr').click(function() 

使用jQuery选择表的容器和应用这样的,而不是!

$('#tableContainer').on('click', 'tr', function(){/*things*/}) 

通过在一个“容器” S任何给定的子结合的点击事件,你知道,即使事情添加到页面加载后的容器中,如该事件被绑定到的元素可点击父母,而不是元素本身。