gpt4 book ai didi

javascript - HTML javascript onclick 事件不适用于输入类型提交

转载 作者:行者123 更新时间:2023-11-29 18:03:37 26 4
gpt4 key购买 nike

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
}

?>

当我按下提交时没有任何反应,但是当我按下 onclick 时 alert() 函数警告框会出现。请帮帮我。 juz 更新后的帖子帮助我检查错误是什么。非常感谢您的帮助。

最佳答案

您没有将 removeButton 参数传递给 myFunction()。尝试:

<input type="submit" onclick="myFunction(this)" class="remove-product" name="delete" value="Remove">

关于javascript - HTML javascript onclick 事件不适用于输入类型提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33086972/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com