Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > JavaScript: для новичков > Проблема с отображением уведомления о покупке


Автор: Witaly90 20.12.2013, 05:39
Здравствуйте!
Проблема вот в чем:
При нажатии на кнопку "Купить" нужно рядом вывести картинку(галочку), чтобы человек видел, что он добавил.
http://best-relax.kiev.ua/123/index.php?route=product/category&path=34 
Все к чему я пришел это появление галочки только в div первого товара, подскажите пожалуйста, что нужно поменять в файле , чтобы выводить галочки возле тех товаров, которые купили?
Отрывок category.tpl
HTML
<div class="cart">
     <script type="text/javascript">
     function addQtyToCart(product_id) {
          var qty = $('.item-' + product_id).val();
         if ((parseFloat(qty) != parseInt(qty)) || isNaN(qty)) {
             qty = 1;
            }
                   addToCart(product_id, qty);
                 } 
</script>
               <input type="text" value="1" size="2" class="item-<?php echo $product['product_id']; ?>" />
                <input type="button" value="<?php echo $button_cart; ?>" onclick="addQtyToCart('<?php echo $product['product_id']; ?>');" class="button" />
      <div id="notification"></div>
      </div>

Отрывок common.js
Код

function addToCart(product_id, quantity) {
    quantity = typeof(quantity) != 'undefined' ? quantity : 1;

    $.ajax({
        url: 'index.php?route=checkout/cart/add',
        type: 'post',
        data: 'product_id=' + product_id + '&quantity=' + quantity,
        dataType: 'json',
        success: function(json) {
            $('.success, .warning, .attention, .information, .error').remove();
            
            if (json['redirect']) {
                location = json['redirect'];
            }
            
            if (json['success']) {
                $('#notification').html('<div class="success" style="display: none;">' + json['success'] + '');
                
                $('.success').fadeIn('slow');
                
                $('#cart-total').html(json['total']);
                
                //$('html, body').animate({ scrollTop: 0 }, 'slow'); 
            }    
        }
    });
}

Буду бесконечно благодарен за любую помощь.
Спасибо!    

Автор: JAYBE 9.1.2014, 13:49
Для этого элемента <div id="notification"></div> лучше задать класс notification, а для <div class="cart"> задать id - id товара. Тогда при success можно будеть что-то делать с этим элементов - $('#id.cart .notification')[метод]();

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)