通过单击删除同一行中存在的链接来删除特定行


Remove particular row by clicking remove link present in the same row

我有表格1st page(test.php(,如下所示

<form method="post" action="newtest.php">
  <input  name="product[]"  type="checkbox" value="1" <?php if(in_array("1", $session_products)) echo "checked='checked'"; ?>  alt="1607.00" />
  <input name="product[]" type="checkbox" value="2" <?php if(in_array("2", $session_products)) echo "checked='checked'"; ?> alt="1848.00" /> 
  <input name="product[]" type="checkbox" value="3" <?php if(in_array("3", $session_products)) echo "checked='checked'"; ?> alt="180.00" />
  <input name="product[]" type="checkbox" value="4" <?php if(in_array("4", $session_products)) echo "checked='checked'"; ?> alt="650.00" />
  <input name="product[]" type="checkbox" value="5" <?php if(in_array("5", $session_products)) echo "checked='checked'"; ?> alt="495.00" />
     <div class="ph-float">
         <input type="submit" name="button" value="Checkout >>" class="ph-button ph-btn-green fm-submit" disabled="true" >
     </div> 
</form>

根据复选框选择,在表格中显示书籍名称,金额和总计,如下所示(newtest.php((请记住,我没有使用数据库,这些值不是来自数据库instad,而是从以下位置获取这些值产品阵列如下所述(

<?php     
	$product = array();
	$product[1] = array('name' => "Text Book of Human Anatomy by B.D.Chaurasiavol 6th edition Vol -I Vol-II Vol-III.", 'price' => 1607);
	$product[2] = array('name' => "Nettars Atlas of Anatomy", 'price' => 1848);
	$product[3] = array('name' => "Genera Anatomy by B.D.Chaurasia", 'price' => 180);
	$product[4] = array('name' => "Inderbir Singh Embryology 10th edition ", 'price' => 650);
	$product[5] = array('name' => "Inderbir Singh Histology ", 'price' => 495);
               
        if(isset($_POST['button']))
	{		 
    	   $first = array();
	   $second = array();
	    foreach ($_POST['product'] as $pId)
	     {
		$first[] = $product[$pId]['name'];
		$second[] = $product[$pId]['price']; 
	     }
	  $bookauthor = count($first);
	  $bookprice = count($second);
	  $max = ($bookauthor > $bookprice ? $bookauthor : $bookprice);
	  echo '<br />';
	  echo '<i style="font-color:#000000;font-weight:bold;text-decoration:underline;font-size:21px; padding-left:110px;margin-top:10px"> List of books you have selected:</i>';
	  echo '<table>';
	  echo '<tr>';
	  echo '<th style="text-align: center">SL No.</th>';
	  echo "<th>Book Name</th>";
	  echo "<th>Amount in INR</th>";
          echo "<th>Action</th>";
	  echo '</tr>';
	   $count = 0;
	   for ($i = 0; $i < $max; $i++)
	    {
		$count++;
		echo '<tr>';
		echo "<td style='text-align: center'>{$count}</td>";
		echo "<td>{$first[$i]}</td>";
		echo "<td>{$second[$i]}</td>";
                echo "<td><a href='#'><i style='color:#F5F5F5;background:#D52020'>REMOVE</i> </a></td>";
		echo '</tr>';
	    }
		$total =  array_sum($second);
		echo '<tr>';
		echo "<td colspan='2' style='font-weight:bold;font-size:14px'>Total Amount</td>";
		echo "<td style='font-weight:bold;font-size:14px;'>{$total}</td>";
		echo "</tr>";
		echo '</table>';
        }
?>

当我单击同一行中显示的 REMOVE 链接时,我想从表中删除特定行,如何实现这一点?链接没问题,或者我应该使用按钮。如果有人写一些代码可能会有所帮助,就像我的新网络一样......提前谢谢。

$('i').click(function(){
    $(this).parent('a').parent('td').parent('tr').remove();
});

该行将被删除,但单击后会转到链接,刷新页面时会立即恢复该行。

在回调末尾添加返回 false; 或 event.preventDefault((; 以防止默认行为:

$(document).ready(function() {
$("#favoriteFoodTable .deleteLink").on("click",function() {
    var tr = $(this).closest('tr');
    tr.css("background-color","#FF3700");
    tr.fadeOut(400, function(){
        tr.remove();
    });
    return false;
});

}(;