javascript - JS:未捕获的类型错误:onlcick 不是函数
问题描述
当我将form
标签放在butto
n 标签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>
解决方案
使用 window.up window.down 因为范围是当前形式而不是像这样的窗口
推荐阅读
- python - 获取迁移错误
- identityserver4 - IdentityServer4 OIDC 请求对象支持
- java - Java 私有静态最终字段和匿名内部类与 Kotlin const val 和对象表达式/声明
- r - 转换为 plotly 时保留 ggplot2 引用
- reactjs - 尝试导航 null 不在评估 C.State 的对象上
- python - 根据相似的列值将单独的熊猫数据框中的列相乘
- c++ - 使用类从双向链表中删除节点
- php - 如何更改列以支持 unicode
- angular - npm 错误!无法读取未定义的属性“解决”
- reactjs - 获取`存储错误:应用程序试图写入一个没有提供类型名的对象,但存储已经包含一个具有类型名的对象`