# 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"/>
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://learnphp.gitbook.io/learnphp/wordpress/tao-nut-cong-san-pham-bang-ajax-ok.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
