这是我尝试过的:
<html>
<head>
<script>
function myFunction() {
var num = document.getElementById("num").value;
if (Number.isInteger(num)) {
document.getElementById("show").innerHTML = "Number is integer";
} else {
document.getElementById("show").innerHTML = "Number is not integer";
}
</script>
</head>
<body>
<input id = "num"></input>
<button onclick = "myFunction()">Submit</button>
<p id = "show">Result Appears Here</p>
</body>
</html>
这里的问题是,即使数字是整数,我始终会得到“number is not integer”的提示。代码应该检查输入是否为整数。谢谢。
""%1
和null%1
都返回0
,因此取模方法有其怪癖。 - RobG