爱玺玺

爱玺玺的生活日记本。wx:lb87626

js通过Math.round(form1.num1.value)!=form1.num1.value判断是不是数字

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
   
    <title>My JSP 'interFace.jsp' starting page</title>
   
 <meta http-equiv="pragma" content="no-cache">
 <meta http-equiv="cache-control" content="no-cache">
 <meta http-equiv="expires" content="0">   
 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
 <meta http-equiv="description" content="This is my page">
 <!--
 <link rel="stylesheet" type="text/css" href="styles.css">
 -->
<script>
function check(){
  if(form1.num1.value==""){
  alert("num1没有填写");
  return false;
  }
  if(Math.round(form1.num1.value)!=form1.num1.value){
  alert("num1不是数字");
  return false;
  }
  if(form1.num2.value==""){
  alert("num2没有填写");
  return false;
  }
  if(Math.round(form1.num2.value)!=form1.num2.value){
  alert("num2不是数字");
  return false;
  }
}
</script>
  </head>
 
  <body>
  <form name="form1" method="post" action="/MyJspSite/test1/myResult.jsp">
    <table style="width:600px; border-collapse:collapse" border="1">
       <tr><td>请输入第一个数</td><td><input type="text" name="num1"/></td></tr>
       <tr><td>选择运算</td><td>
       <select name="flag">
       <option value="+">+</option>
       <option value="-">-</option>
       <option value="*">*</option>
       <option value="/">/</option>
       </select>
       </td></tr>
       <tr><td>请输入第二个数</td><td><input type="text" name="num2"/></td></tr>
       <tr><td>&nbsp;</td><td><input type="submit" onclick="return check()" value="计算"/></td></tr>
    </table>
    </form>
  </body>
</html>


发表评论:

Powered By Z-BlogPHP 1.4 Deeplue Build 150101

Copyright Your WebSite.Some Rights Reserved.

蜀ICP备11021721号-5