当我点击第一行时,它会显示输出 当我点击第二个时,它也会显示,但第一行没有被隐藏 它仍在显示。
所有行都应该发生,而不仅仅是前两行。
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 :(得分:0)
JQuery有一个以前的选择器...也许你可以使用它?
从jquery文档页面获取的代码:$( "li.third-item" ).prev().css( "background-color", "red" );
基本上你可以这样做:$('something').click(function() { $(this).prev().hide(); })
或$(this).parent().prev().hide();
答案 1 :(得分:0)
我不完全确定PHP是如何工作的,但是如果您正在制作的表是动态的(在您的javascript运行之后),那么您的jquery选择器无法工作..
$('#table_struct tr').click(function()
使用jquery选择表的容器并改为应用!
$('#tableContainer').on('click', 'tr', function(){/*things*/})
通过将click事件绑定到任何给定子级的“容器”上,您知道即使在pageLoad之后将事物添加到容器中,当事件绑定到父级时,元素也是可单击的,而不是元素本身。