Сделать кнопку не активной, если выбрано кол-во товара меньше, чем 5 шт.
Привет всем. Помогите со скриптом.
На странице перечень товаров, необходимо для двух: productitem_132 и productitem_133 сделать так, чтобы кнопка добавления в корзину была активна, если выбрано кол-во минимум 5 шт. <div class="productitem_132"> <input class="product_minus" type="button" onclick="..."> <input type="text" name="quantity132" id="quantity132" " value="1"> <input class="product_plus" type="button" onclick="..."> <a class="button_buy" id="productlink132" href="...">В корзину</a> </div> |
Цитата:
|
Цитата:
|
Может как-то так?
const ids = [132, 133];
const minQuantity = 5;
[].forEach.call(document.querySelectorAll(ids.map(id => `#quantity${id}`).join(', ')), node => {
node.addEventListener('input', e => {
const id = node.id.replace(/\D+?/g, '');
document.getElementById(`productlink${id}`).disabled = +node.value.trim() < minQuantity;
});
});
|
Quark_,
Только disabled будет работать с button или input для ссылок другой механизм. |
| Часовой пояс GMT +3, время: 04:10. |