Answer the question
In order to leave comments, you need to log in
How to implement delayed start of a function?
There is a future online store. According to the layout in the product blocks, there are 2 types of displaying the number of products: span and input.
Behavioral logic: initially only the span is displayed. When you click on it, it changes to an input and the focus is transferred to it (it becomes possible to change the number of units of the product.) After losing the focus, hide the input and show the span, passing the number that was entered in the input into it.
Initially, the implementation was simpler. Banal input.amount and span.amount selectors. Everything worked fine in Chrome. But Ms. FireFox caused a lot of problems.
$("span.amount").click(function() {
$(this).addClass('hidden');
$(this).siblings("input.amount").removeClass('hidden').focus();
});
$("input.amount").focusout(function() {
$(this).addClass('hidden');
$(this).siblings("span.amount").removeClass('hidden').html($(this).val() + ' шт.');
});
var inputCurrent = '';
$('input.amount').hide();// при загрузке прячем все инпуты
$('span.amount').click(function() { // клик по спану
var inputCurrent = $(this).siblings('input.amount'); // передаем в переменную текущий инпут
$(this).hide(); // прячем текущий спан
inputCurrent.show().focus(); // показываем текущий инпут и передаем ему фокус
});
inputCurrent.focusout(function() { // при потере инпутом фокуса:
$(this).hide(); // прячем этот инпут
$(this).siblings('span.amount').show().html($(this).val() + ' шт.'); // показываем текущий спан и передаем в него параметры из инпута
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question