JS 判断是否是数字
程序员文章站
2022-07-02 15:27:32
...
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<input id="demo" type="text">
<script>
function myFunction(){
var x = document.getElementById("demo").value;
if(x == "" || isNaN(x)){
console.info(x+" :不是数字");
}else{
console.info(x+" :是数字");
}
}
</script>
<button type="button" onclick="myFunction()">点击这里</button>
</body>
</html>
效果图: