<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>计算是否为数字</title>
</head>
<body>
<input type="text" id="txt1">
<input type="button" id="but" value="开始计算">
<input type="text" id="txt2" disabled>
</body>
<script>
var txt1 =document.getElementById("txt1");
var txt2 =document.getElementById("txt2");
var but =document.getElementById("but");
but.onclick = function(){
txt2.value = num(txt1.value);
}
function num(a) {
if (isNaN(a)) {
return "这不是数字!";
} else {
return "这是纯数字!";
}
}
</script>
</html>