Jump to content
  • разработка интернет магазинов на opencart
  • доработка интернет магазинов на opencart

Немного изменить скрипт


MaJIon
 Share

Recommended Posts

Здравствуйте, как дописать скрипт иким обвместе, чтобы при клике добавляло или отнимало от значения в сотых, то есть шаг  0.25 сгделать?


 

<script><!--
$(function() {
	$(document).on('click', ".number-spinner a", function(e){
		e.preventDefault();
		btn = $(this);
		input = btn.closest('.number-spinner').find('input');
		btn.closest('.number-spinner').find('a').prop("disabled", false);
		if (btn.attr('data-dir') == 'up') {
			if ( input.attr('max') == undefined || parseInt(input.val()) < parseInt(input.attr('max')) ) {
				input.val(parseInt(input.val())+1);
				input.trigger('change');
			}else{
				btn.prop("disabled", true);
			}
		} else {
			if ( input.attr('min') == undefined || parseInt(input.val()) > parseInt(input.attr('min')) ) {
				input.val(parseInt(input.val())-1);
				input.trigger('change');
			}else{
				btn.prop("disabled", true);
			}
		}
	});
	$(document).on('change', '.dc-quantity-spinner-list', function(){
		if($(this).parents('.product-thumb').find('[onclick^="cart.add"]').length){
			var buttonCart = $(this).parents('.product-thumb').find('[onclick^="cart.add"]');
			var productId = buttonCart.attr('onclick').match(/\d+/);
			buttonCart.attr('data-product-id', productId).removeAttr('onclick');
		}
	});
	$(document).on('click', '[data-product-id]', function(){
		cart.add($(this).data('product-id'), $(this).parents('.product-thumb').find('.dc-quantity-spinner-list').val());
	});
});
//--></script> 

 

Link to comment
Share on other sites


Если я правильно понял, заменить везгде parseInt на parseFloat и вместо -1  +1 написать -0.25 +0.25 соответственно.

Link to comment
Share on other sites


9 часов назад, GetWeb сказал:

Если я правильно понял, заменить везгде parseInt на parseFloat и вместо -1  +1 написать -0.25 +0.25 соответственно.

Спасипотому что, помогло)) 
Еещё вопрос как сгделать, ик чтобы округляло 1000 и не переслитывало как на скриншоте  download.jpg.53761dcafc2b0637357012da59910153.jpg
У меня шаги у всех товаров разные и поэтому я в скрипте 1 заменил на input.attr('step')) в поле когдачества товаров, но вот если у меня шаг, к примеру, 0.100, то на увеличении к 0.300 у меня не округляет. Надо чтобы было 0.300 

Link to comment
Share on other sites


1 час назад, MaJIon сказал:


Еещё вопрос как сгделать, ик чтобы округляло 1000 и не переслитывало как на скриншоте  download.jpg.53761dcafc2b0637357012da59910153.jpg.

К примеру ик: input.val((parseFloat(input.val())+1).toFixed(3));

Link to comment
Share on other sites


Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

On our site, cookies are used and personal data is processed to improve the user interface. To find out what and what personal data we are processing, please go to the link. If you click "I agree," it means that you understand and accept all the conditions specified in this Privacy Notice.