我真的被以下内容卡住了。我有一个动态生成的表,它显示了一种购物清单,其中包含一些从API获得的数据,比如产品名称和产品价格。
当我点击购物按钮时,我想要一个模式,显示总结购买的文本,并单击确认按钮,将数据保存在数据库中。
在这种情况下,我将动态变量存储在元素id和/或value中。但是,如果我现在就想要-as --存储两个以上的变量呢?
所以,这是我的代码:
<table class="sortable" id="myTable">
<thead >
<tr>
<th onclick="sortTable(0)">Product</th>
<th onclick="sortTable(1)">Price</th>
<th onclick="sortTable(1)">Amount</th>
<th onclick="sortTable(3)"></th>
</tr>
</thead>
<tbody>
<?php
foreach ($result as $doc) {
$price = $doc['2. price'];
$name = $doc['1. symbol'];
$rd_price = round($price, 2);
?>
<tr>
<td><?php echo $name; ?></td>
<td class="product_price"><?php echo $rd_price; ?></td>
<td><input type="text" id= "product_qty_" name="qty" class="product_qty" value="0"></td>
<td class="amount_sub_total">0</td>
<td><button class="sbtn" data-id="sbtn" data-name="<?php echo $name; ?>" data-price="<?php echo $rd_price; ?>" data-toggle = "modal" data-target = "#myModal" onclick="showDetails(this)">
<i class="fas fa-shopping-cart"></i>
</button></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
<!-- Modal -->
<div class = "modal fade" id = "myModal" tabindex = "-1" role = "dialog"
aria-labelledby = "myModalLabel" aria-hidden = "true" data-backdrop="false" style="">
<div class = "modal-dialog">
<div class = "modal-content">
<div class = "modal-header">
<h4 class = "modal-title" id = "myModalLabel">
Purchase order
</h4>
<button type = "button" class = "close" data-dismiss = "modal" aria-hidden = "true" style="background-color: transparent; margin-top: -20px; float: right; color: #4d4646; width: 10px; height: 10px;">
×
</button>
</div>
<div class = "modal-body">
<p><span id="value"></span></p>
</div>
<div class = "modal-footer">
<button type = "button" id="modal_yes_btn" class = "btn btn-primary" style="width: 80px; height: 40px;" onclick="yesBtnFunction()">
Yes
</button>
<button type = "button" class = "btn btn-default" data-dismiss = "modal" id="modal_no_btn" style="width: 80px; height: 40px;" onclick="noBtnFunction()">
No
</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<script>
var product_quantity;
var sub_total;
$( document ).ready(function() {
$(document).on("input paste keyup", ".product_qty", function( event ) {
var product_price = 0;
var gst_amount = 0;
var sub_total = 0;
var total_qty = 0;
var grand_total = 0;
product_quantity = $(this).val();
product_price = $(this).parent().prev().html();
sub_total = product_price * product_quantity;
var sbt_display = $(this).parent().next().html(sub_total);
$(this).parent().next().html(sub_total)
});
});
function showDetails(button) {
var name = $(this).attr("data-name");
var price = $(this).attr("data-price");
var selectedAmount = product_quantity;
$.ajax({
url: "customer.php",
method: "GET",
data: {"name": name, "price": price, "selectedAmount": selectedAmount},
success: function(response){
$("#value").text(response);
}
});
}
</script>
customer.php
<?php
$name = $_GET["name"];
$price = $_GET["price"];
$selectedAmount = $_GET["selectedAmount"];
$totalprice = $price * $selectedAmount;
echo "You are about to purchase " . $selectedAmount . " shares of " . $name . " at $ " . $price . " per unit. " . "Total price: $ " . $totalprice . " Do you want to proceed?";
?>
但是,如果我需要存储两个以上的值,或者我只想留下一个非变量Id,我该怎么做呢?
在此之前,非常感谢您。
https://stackoverflow.com/questions/50689653
复制相似问题