Ответы пользователя по тегу JavaScript
  • Счетчик на js по кликам?

    @pythonist1234
    Правильно так:
    <input type="button" id="buttonCountPlus" value="+">
    <input type="button" id="buttonCountMinus" value="-">
    <div id="buttonCountNumber">1</div>
    <input type="hidden" value="1" id="num" name="num">

    let buttonCountPlus = document.getElementById("buttonCountPlus");
    let buttonCountMinus = document.getElementById("buttonCountMinus");
    let count = document.getElementById("buttonCountNumber");
    let count2 = document.getElementById("num");
    let number = 1;
    let price = 350;
    
    buttonCountPlus.onclick = function() {
        if (number <= 3) {
            number++;
            count.innerHTML = number;
            count2.value = number * price;
        }
    };
    
    buttonCountMinus.onclick = function() {
       if (number >= 2) {
           number--;
           count.innerHTML = number;
           count2.value = number * price;
        }
    }:
    Ответ написан
    6 комментариев