【发布时间】:2016-08-29 02:11:47
【问题描述】:
我有两个按钮(+ 和 -)和一个值为 10 的输入框。输入必须只取 0 到 10 之间的值,我无法弄清楚为什么在我到达之后我会变得未定义输入框上的 0 或 10。我尝试使用 parseInt 作为值。但也许我没有在正确的地方做这件事。非常感谢您的帮助。
var fighterScore1 = document.getElementById("fighterScore1");
fighterScore1.value = 10;
var fighter1Inc = document.getElementById("fighter1Inc");
var valor = 10;
fighter1Inc.onclick = function (valor) {
fighterScore1.value = increaseValue(valor);
};
fighter1Dec.onclick = function (valor) {
fighterScore1.value = decreaseValue(valor.value);
};
function decreaseValue() {
if (valor <= 0 ) {
} else {
valor--;
return valor;
}
};
function increaseValue() {
if (valor >= 10 ) {
valor = 10;
} else {
valor++;
valor = valor;
return valor;
}
};
<div id="rwid1">
<button id="fighter1Inc">+</button>
<input type="text" id="fighterScore1" maxlength="10" onkeypress='return event.charCode >= 48 && event.charCode <= 57'>
<button id="fighter1Dec">-</button>
</div><!--/rwid-->
【问题讨论】:
-
您将参数传递给 increaseValue 但函数本身不接受参数?
标签: javascript undefined counter inputbox