JQuery:如何将PHP数据从div传递给div

时间:2018-05-09 14:20:59

标签: javascript jquery html

至于我的HTML代码是

<div class="right">
      <h2>Product Detail</h2>
      <div  id="righttop"></div>
      <button id="Add">Add</button>
</div>

<div  class="rightbot">
    <h2>Shopping Car</h2>
    <div id="rightbot"></div>
</div>

PHP就是

mysqli_select_db($con,"products");
$sql="SELECT product_id, product_name, unit_price, unit_quantity, in_stock FROM products WHERE product_id = '".$productid."'";
$result = mysqli_query($con,$sql);

echo "<table>";
echo "<th>Product Name</th>";
echo "<th>Unit Price</th>";
echo "<th>Unit Quantity</th>";
echo "<th>In Stock</th>";
while($row = mysqli_fetch_array($result)) {
    echo "<tr  id='detail'>";
    echo "<td>" . $row['product_name'] . "</td>";
    echo "<td>" . $row['unit_price'] . "</td>";
    echo "<td>" . $row['unit_quantity'] . "</td>";
    echo "<td>" . $row['in_stock'] . "</td>";
    echo "</tr>";
}
echo "</table>";
echo $_POST['detail'];
mysqli_close($con);
?>

div#righttop被其他按钮更改。

如何将当前内容从div#righttop传递到div#rightbot

1 个答案:

答案 0 :(得分:0)

如果您打算将righttop的内容转移到rightbot,这是一种方法。点击按钮,在更改righttop中的任何内容之前,请执行以下操作:

$('#rightbot').html($('#righttop').html());