提问人:adrian 24 提问时间:11/12/2023 最后编辑:Kazzadrian 24 更新时间:11/12/2023 访问量:39
如何将 html 插入到不同的 div 中?
How can I insert htmls into different divs?
问:
<?php
include('BD.php');
session_start();
if (!isset($_SESSION['carrito'])) {
$_SESSION['carrito'] = array();
}
if (isset($_POST['idProducto']) && isset($_POST['valor'])) {
$idProducto = $_POST['idProducto'];
$cantidad = $_POST['valor'];
$_SESSION['carrito'][$idProducto]['cantidad'] = $cantidad;
}
$Carrito = $_SESSION['carrito'];
?>
<?php if ($Carrito): ?>
<?php foreach ($Carrito as $idProducto => $Producto): ?>
<?php
$cantidad = isset($Producto['cantidad']) ? $Producto['cantidad'] : 1;
$OP = $Producto['PrecioPX'] * $cantidad;
@$Total += $OP;
?>
<tr>
<td class="product-thumbnail">
<img src="LA-TEC/<?php echo $Producto['FOTOPX']; ?>" alt="Image" class="img-fluid" width="120px" heigth="75px">
</td>`
<td class="product-name">
<h2 class="h5 text-black"><?php echo $Producto['NombrePX']; ?></h2>
</td>
<td>$ <?php echo $Producto['PrecioPX']; ?></td>
<td>
<div class="input-group mb-3" style="max-width: 120px;">
<input type="number" class="Cantidad" value="<?php echo $cantidad ?>" placeholder=""
aria-label="Example text with button addon" aria-describedby="button-addon1"
name="CA" id="CA_<?php echo $idProducto; ?>" style="width:100px;">
</div>
</td>
<td>$ <?php echo $OP; ?></td>
<td><a href="#" class="btn btn-primary height-auto btn-sm" onclick="Eliminar('<?php echo $Producto['IDPX']; ?>');">X</a></td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
<!--
Subtotal
<strong>$230.00</strong>
Total
<strong><?php echo $Total;?></strong>
Proceed To
Checkout
-->
$(document).ready(function(){
$.ajax({
url: 'Inicio_Secc/PrecioCant.php',
method: 'POST',
dataType:'text',
success: function(data) {
$('#Carrito').html(data);
$('#Total').html(data);
},
error: function(jqXHR, textStatus, errorThrown) {
console.error('Error al enviar la solicitud:', errorThrown);
}
});
});
<div id="Total"></div>
<tbody id="Carrito"></tbody>
我在 php 中有 2 个 html 块,我想要的是将注释块插入到 id = Total 的 div 中,另一个带有循环的 php html 块反映在 id = Cart 的 div 中,但在 2 个 div 中反映了 html,我想要它们分开, 帮助
答: 暂无答案
评论