Javascript 在opencart中加载时出现错误
我编辑了我的Javascript 在opencart中加载时出现错误,javascript,php,html,opencart,Javascript,Php,Html,Opencart,我编辑了我的结帐/cart.tpl,起初一切看起来都很好,但当我添加购物车时,一些代码会自动更改,一切都会很奇怪 例子 1-当我进入网站并查看购物车时,一切看起来都很好: 2-缺陷/错误。当我更新我的购物车时,当我点击“添加购物车”时,只显示我购物车的这一部分,没有价格和结帐等: HTML/cart.TPL <div id="cart"> <a href="#" data-loading-text="<?php echo $text_loading; ?>"
结帐/cart.tpl
,起初一切看起来都很好,但当我添加购物车时,一些代码会自动更改,一切都会很奇怪
例子
1-当我进入网站并查看购物车时,一切看起来都很好:
2-缺陷/错误。当我更新我的购物车时,当我点击“添加购物车”时,只显示我购物车的这一部分,没有价格和结帐等:
HTML/cart.TPL
<div id="cart">
<a href="#" data-loading-text="<?php echo $text_loading; ?>"><img src="images/bag.png" alt="Bag" />Cart: <span id="cart-total"><?php echo $text_items; ?></span></a>
<div class="cart_menu">
<?php if ($products || $vouchers) { ?>
<div class="cart_items">
<?php foreach ($products as $product) { ?>
<div class="c_item_img floatleft">
<?php if ($product['thumb']) { ?>
<a href="<?php echo $product['href']; ?>"><img src="<?php echo $product['thumb']; ?>" alt="<?php echo $product['name']; ?>" title="<?php echo $product['name']; ?>" /></a>
<?php } ?>
</div>
<div class="c_item_totals floatleft">
<div class="c_item_totals_detail floatleft">
<a href="<?php echo $product['href']; ?>"><h5><?php echo $product['name']; ?></h5></a>
<span><?php echo $product['quantity']; ?> x <?php echo $product['total']; ?></span>
</div>
<div class="close_icon_cart floatleft">
<img src="images/close.png" onclick="cart.remove('<?php echo $product['key']; ?>');" title="<?php echo $button_remove; ?>" alt="" />
</div>
</div>
<?php } ?>
</div>
<div class="cart_totals">
<?php foreach ($totals as $total) { ?>
<div class="c_totals_left floatleft">
<p></p>
</div>
<div class="c_totals_right floatleft">
<p><?php echo $total['title']; ?> <?php echo $total['text']; ?></p>
</div>
<?php } ?>
</div>
<div class="cart_view_bottom">
<div class="c_totals_left floatleft">
<a href="<?php echo $cart; ?>"><?php echo $text_cart; ?></a>
</div>
<div class="c_totals_right floatleft">
<a href="<?php echo $checkout; ?>"><?php echo $text_checkout; ?></a>
</div>
</div>
<?php } else { ?>
<div class="cart_items">
<p class="text-center"><?php echo $text_empty; ?></p>
</div>
<?php } ?>
</div>
</div>
x
');“title=”“alt=”“/>
.JS
<script type="text/javascript"><!--
$('#button-cart').on('click', function() {
$.ajax({
url: 'index.php?route=checkout/cart/add',
type: 'post',
data: $('#product input[type=\'text\'], #product input[type=\'hidden\'], #product input[type=\'radio\']:checked, #product input[type=\'checkbox\']:checked, #product select, #product textarea'),
dataType: 'json',
beforeSend: function() {
$('#button-cart').button('loading');
},
complete: function() {
$('#button-cart').button('reset');
},
success: function(json) {
$('.alert, .text-danger').remove();
$('.form-group').removeClass('has-error');
if (json['error']) {
if (json['error']['option']) {
for (i in json['error']['option']) {
var element = $('#input-option' + i.replace('_', '-'));
if (element.parent().hasClass('input-group')) {
element.parent().after('<div class="text-danger">' + json['error']['option'][i] + '</div>');
} else {
element.after('<div class="text-danger">' + json['error']['option'][i] + '</div>');
}
}
}
if (json['error']['recurring']) {
$('select[name=\'recurring_id\']').after('<div class="text-danger">' + json['error']['recurring'] + '</div>');
}
// Highlight any found errors
$('.text-danger').parent().addClass('has-error');
}
if (json['success']) {
$('.breadcrumb').after('<div class="alert alert-success">' + json['success'] + '<button type="button" class="close" data-dismiss="alert">×</button></div>');
$('#cart-total').html(json['total']);
$('html, body').animate({ scrollTop: 0 }, 'slow');
$('#cart > div').load('index.php?route=common/cart/info .cart_menu .cart_items');
}
}
});
});
//--></script>
我已经尝试将所有div类都放在JavaScript中,但不幸的是,它没有起作用。我几乎可以肯定,您的问题是由于您使用了id“cart”“在您的
结帐/cart
模板中,该模板已由模块/cart
处理的购物车模块使用。重要的是要理解这是两种不同的东西,cart
id需要是唯一的——特别是当您使用javascript更新其内容时
尝试将checkout/cart.tpl中的id更改为“cart”以外的内容