1
<h1>我的第一段 JavaScript</h1>
2
<p>请输入数字。如果输入值不是数字,浏览器会弹出提示框。</p>
3
<input id="demo" type="text">
4
<script>
5
function myFunction() {
6
var x = document.getElementById("demo").value;
7
if (x == "" || isNaN(x)) {
8
alert("不是数字");
9
}
10
}
11
</script>
12
<button type="button" onclick="myFunction()">点击这里</button>