首页 > 解决方案 > JS:未捕获的类型错误:onlcick 不是函数

问题描述

当我将form标签放在button 标签id="paybutton" 功能上时,它运行良好。但是当我将form标签放在 上时div class="form-group,向上和向下按钮不起作用。我已经添加type="button"并尝试更改input type ="button",但它仍然无法正常工作。

<script>
    var up = function(max) {
        document.getElementById("mynumber").value = parseInt(document.getElementById("mynumber").value) + 1;
        if (document.getElementById("mynumber").value >= parseInt(max)) {
            document.getElementById("mynumber").value = max;
        }
        document.getElementById("amount").value = parseInt(document.getElementById("mynumber").value) * 5000;
        if (document.getElementById("amount").value >= 50000) {
            document.getElementById("amount").value = 50000;
        }
    }

    function down(min) {
        document.getElementById("mynumber").value = parseInt(document.getElementById("mynumber").value) - 1;
        if (document.getElementById("mfFFfFFynumber").value <= parseInt(min)) {
            document.getElementById("mynumber").value = min;
        }
        document.getElementById("amount").value = parseInt(document.getElementById("mynumber").value) * 5000;
        if (document.getElementById("amount").value <= 5000) {
            document.getElementById("amount").value = 5000;
        }
    }
</script>


<form method="post" action="/kakaoPay">
    <!--  ??? ?? -->
    <div class="form-group">
        <label>??? ? (1??? : 5??): </label>
        <div class="input-group">
            <div class="input-group-btn">
                <button type="button" id="down" class="btn btn-default" onclick="down('1')">
                    <span class="glyphicon glyphicon-minus"></span>
                </button>
            </div>
            <input type="text" name="mybumber" id="mynumber" class="form-control input-number" value="1" />
            <div class="input-group-btn">
                <button type="button" id="up" class="btn btn-default" onclick="up('10')">
                    <span class="glyphicon glyphicon-plus"></span>
                </button>
            </div>
        </div>
        <output type="number" id="amount" name="total" class="form-control input-number"></output>
    </div>
    -
    <h1> ?? </h1>
    -
    <!-- <form method="post" action="/kakaoPay">  -->
    - <button name="paybutton" id="paybutton"> ?? </button> -
</form>

标签: javascripthtml

解决方案


使用 window.up window.down 因为范围是当前形式而不是像这样的窗口


推荐阅读