JavaScript如何驗證輸入的不是數字

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" language="JavaScript">

function yanzheng(){
//這裏是判斷輸入的是否是數字
if(Math.round(form1.text1.value)!=form1.text1.value){
alert("輸入無效,請輸入一個數字");
form1.text1.focus();
return false;
}
}
</script>
</head>
<body>
<form action="" name="form1">
請輸入一個數字:<input type="text" name="text1"><br>
<input type="submit" value="提交" onClick="return yanzheng();">
</form>
</body>
</html>
相關文章
相關標籤/搜索