JavaScript:验证输入
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<meta charset="utf-8" />
<script src="jQuery/jquery-2.2.0.min.js"></script>
<script src="bootstrap/js/bootstrap.min.js"></script>
<link rel="stylesheet"href="bootstrap/css/bootstrap.min.css" />
</head>
<body>
<div class="container"style="padding:50px">
<h3>JavaScript:验证输入</h3>
<p>请输入数字。如果输入值不是数字,浏览器会弹出提示框。</p>
<input type="text" id="demo"/>
<hr />
<button class="btn btn-primary"onclick="myFunction()">点击按钮</button>
<script>
function myFunction() {
var v = document.getElementById("demo").value;
if (v == "" || isNaN(v)) {
alert(v + "不是数字")
}
else {
alert(v+"是数字")
}
}
</script>
</div>
</body>
</html>