我目前正在使用谷歌地图并尝试使用输入验证。我要求用户使用 0 到 20 之间的数字来设置我的位置的缩放。
下面是我正在使用的代码。第一个if
语句对于任何超过 20 的数字都非常有效,但是当我使用 0 和 -1 之类的数字时,第二个语句不起作用(例如。)
有什么建议可以解决这个问题吗?
function inputIsValid() {
console.log("Inside inputIsValid function");
//Check for Above 20
if (document.getElementById("txtZoom").value > 20) {
alert("Please insertAmount between 0 and 20");
document.getElementById("txtZoom").focus();
return false;
//Check for Number below 0
if (document.getElementById("txtZoom").value < 0) {
alert("Please insertAmount between 0 and 20");
document.getElementById("txtZoom").focus();
return false;
}
}
}