Tạo nút cộng sản phẩm bằng ajax (ok)

Bước 1: Nạp file
jQuery(document).ready(function($) {
  function startSlider() {
    interval = setInterval(function() {
      jQuery('#slider ul').animate({ 'margin-left': '-=500' }, 1000, function() {
        jQuery('#slider ul li:first').appendTo('#slider ul');
        jQuery('#slider ul').css('margin-left', 0);
      });
    }, 4000);
  }

  function pauseSlider() {
    clearInterval(interval);
  }
  startSlider();
  jQuery('#slider ul').on('mouseenter', pauseSlider).on('mouseleave', startSlider);
});
jQuery('input.qty:not(.product-quantity input.qty)').each(function() {
  var min = parseFloat(jQuery(this).attr('min'));

  if (min && min > 0 && parseFloat(jQuery(this).val()) < min) {
    jQuery(this).val(min);
  }
});
jQuery(document).on('click', '.plus, .minus', function($) {
  // Get values
  var $qty = jQuery(this).closest('.quantity').find('.qty'),
    currentVal = parseFloat($qty.val()),
    max = parseFloat($qty.attr('max')),
    min = parseFloat($qty.attr('min')),
    step = $qty.attr('step');
  jQuery('#chan').removeAttr('disabled');
  // Format values
  if (!currentVal || currentVal === '' || currentVal === 'NaN') currentVal = 0;
  if (max === '' || max === 'NaN') max = '';
  if (min === '' || min === 'NaN') min = 0;
  if (step === 'any' || step === '' || step === undefined || parseFloat(step) === 'NaN') step = 1;
  // Change the value
  if (jQuery(this).is('.plus')) {

    if (max && (max == currentVal || currentVal > max)) {
      $qty.val(max);
    } else {
      $qty.val(currentVal + parseFloat(step));
    }
  } else {

    if (min && (min == currentVal || currentVal < min)) {
      $qty.val(min);
    } else if (currentVal > 0) {
      $qty.val(currentVal - parseFloat(step));
    }
  }
  // Trigger change event
  $qty.trigger('change');
});
Bước 2: Vào file quantity - input.php thêm hai trường input <
  input type = "button"
value = "-"
class = "minus" / >
  <input type="button" value="+" class="plus"/>

Last updated