2015-03-13 40 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任何給定的子結合的點擊事件,你知道,即使事情添加到頁面加載後的容器中,如該事件被綁定到的元素可點擊父母,而不是元素本身。