<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
#check .txt{
padding: 5px;
}
#check .bth{
margin: 8px 0;
}
</style>
</head>
<body>
<div id="check">
<h3>输入文字验证:</h3>
<input type="text" placeholder="请输入字符串内容:" class="txt" id="text">
<div>
<button onclick="bb()" class="bth">验证</button>
</div>
<div id="result"></div>
</div>
<script>
function bb(){
var num = document.getElementById('text').value;
var res = document.getElementById('result');
var isNum = isNaN(Number(num))?false:true;
res.innerText = isNum?'数字':'字符'}
</script>
</body>
</html>
判断输入的是字符还是数字