Не меняется сумма в input
Вложений: 2
Добрый вечер!
На сайте есть мини-магазин. Там действует система скидок, если количество больше чем 12, то цена меняется, но она изменилась только внешне, при добавлении товара цена не меняется. Вот эта страница: https://advanced.cn.ua/order Пример ячейки с товаром: <tr> <td><img src="img/order/ballon.png" alt="НПУ POLYNOR"></td> <td><span id="cena">280</span> <div class="number"> <span style="user-select: none;padding:3px 9px 3px 9px;" class="minus">-</span> <input style="user-select: none;background-color: #fff;" id="inp"POLYNOR" type="text" value="0" size="5" /> <span style="user-select: none;" class="plus">+</span> </div> </td> </tr> "Калькулятор": $(function() { var table = $(".order-table"), div = table.find(".number"), input = div.find("input").get(), total = $(".order-end-form>input:text"); function sum() { var n = input.reduce(function(s, el) { var val = +el.value || 0, price = +el.dataset.price || 0; val < 0 && (val = 0); return s + val * price }, 0); total.val(n) } div.each(function(indx, el) { var price = parseInt($(el).prev().text()), input = $("input", el).on({ input: sum })[0]; input.dataset.price = price; $(el).on("click", ".minus, .plus", function(event) { val = +input.value || 0; $(event.target).is(".minus") ? val-- : val++; val < 0 && (val = 0); input.value = val; sum() }) }) }); Замена цены: <script> function cena(){ var a = [[120,250,'#0F0'],[48,260,'#590'],[12,270,'#950'],[1,280,'#F00']].find(el => el[0] <= (+inp.value||1)), cena = document.querySelector("#cena"); cena.textContent = a[1]; cena.style.color = a[2]; }; document.querySelector('#inp').addEventListener("input", cena, false); document.body.addEventListener("click", cena, false); window.addEventListener("DOMContentLoaded", cena, false); </script> Фото ячейки: |
Часовой пояс GMT +3, время: 17:19. |