我正在使用三元运算符来检查用户输入是否为数字。但是,当我按下检查按钮时,无论我输入数字还是字母,都会显示警告信息,请输入一个数字"。这是我的代码。
<label style = "font-size:40px">Please Enter A Number Here: </label><input type = "text" id = "num" style = "font-size:40px">
<button type = "button" onclick = "check()">Check</button>
<script>
function check() {
var input = document.getElementById("num");
var check = /^[0-9]*$/;
(!check.test(input)) ? window.alert("You have only entered numeric characters! Please proceed to press one of the other buttons.") : window.alert("Please enter only numbers!")
}
</script>