function myAlert(){
alert("yo");
}
/* Recalculate cart */
function recalculateCart()
{
var subtotal = 0;
/* Sum up row totals */
$('.product').each(function () {
subtotal += parseFloat($(this).children('.product-line-price').text());
});
/* Calculate totals */
}
/* Update quantity */
function updateQuantity(quantityInput)
{
/* Calculate line price */
var productRow = $(quantityInput).parent().parent();
var price = productRow.children('.product-price').text();
var quantity = $(quantityInput).val();
var linePrice = price * quantity;
/* Update line price display and recalc cart totals */
productRow.children('.product-line-price').each(function () {
$(this).fadeOut(fadeTime, function() {
$(this).text(linePrice.toFixed(2));
recalculateCart();
$(this).fadeIn(fadeTime);
});
});
}
/* Remove item from cart */
function myFunction(removeButton)
{
/* Remove row from DOM and recalc cart total */
var productRow = $(removeButton).parent().parent();
productRow.slideUp(fadeTime, function() {
productRow.remove();
recalculateCart();
});
return true;
}

<?php
session_start();
mysql_connect('localhost','root','');
mysql_select_db('ecommerce');
if(isset($_SESSION['username'])){
?>
<div class="shopping-cart">
<div class="column-labels">
<label class="product-image">Image</label>
<label class="product-details">Product</label>
<label class="product-price">Price</label>
<label class="product-quantity">Quantity</label>
<label class="product-removal">Remove</label>
<label class="product-line-price">Total</label>
</div>
<?php
$query = mysql_query("SELECT * FROM cart");
while($array=mysql_fetch_assoc($query)){
$dbtitle = $array['name'];
$dbprice = $array['price'];
$dbdescription = $array['description'];
$dbproductid = $array['product_code'];
echo $dbproductid;
?>
<div class="product">
<div class="product-image">
</div>
<div class="product-details">
<div class="product-title"><?php echo $dbtitle; ?></div>
<p class="product-description"><?php echo $dbdescription; ?></p>
</div>
<div class="product-price"><?php echo $dbprice; ?></div>
<div class="product-quantity">
<input id="quantity-option" type="number" value="2" min="1">
</div>
<form action="cart.php" method="post">
<input type="submit" onclick="myFunction(this)" class="remove-product" name="delete" value="Remove">
<input type="hidden" name="remove_item" value="<?php echo $dbproductid; ?>">
</form>
<div id="js-price" class="product-line-price"></div>
</div>
<?php
}
?>
&#13;
当我按提交时没有任何反应,但是当我按下点击alert()
功能警告框时会出现。请帮帮我。 juz更新后帮助我检查错误是什么。你的帮助将非常感激。
答案 0 :(得分:4)
您没有将removeButton
参数传递给myFunction()
。试试:
<input type="submit" onclick="myFunction(this)" class="remove-product" name="delete" value="Remove">
答案 1 :(得分:0)
为什么不使用jquery来实现这个功能
$("#btn").click(function(e){
/* Remove item from cart */
e.preventDefault();
/* Remove row from DOM and recalc cart total */
var productRow = $("#btn").parent().parent();
productRow.slideUp(fadeTime, function() {
productRow.remove();
recalculateCart();
});
return true;
});
您的HTML: -
<form action="cart.php" method="post">
<input type="submit" id="btn" class="remove-product" name="delete" value="Remove">
<input type="hidden" name="remove_item" value="<?php echo $dbproductid; ?>">
</form>