求助!琢磨了好久,求大神解答!!!
<%--
Document : cal
Created on : 2015-10-12, 14:21:51
Author : acer
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>计算器</title>
<script>
function isNumber(str)
{
var num = "0123456789.-";
for(var i=0;i<str.length;i++)
{
var ch = str.charAt(i);
if(num.indexOf(ch)==-1)
return false;
}
return true;
}
function check()
{
var n1 = document.getElementById("num1").value;
var n2 = document.getElementByld("num2").value;
if(!isNumber(n1)||!isNumber(n2))
{
alert("请输入数字!");
return false;
}
return true;
}
</script>
</head>
<%
String num1 = request.getParameter("num1");
String num2 = request.getParameter("num2");
String operator = request.getParameter("operator");
if(num1==null)
num1 = "0";
if(num2==null)
num2 = "0";
if(operator==null)
operator = "+";
double n1 = Double.parseDouble(num1);
double n2 = Double.parseDouble(num2);
double result = 0;
if(operator.equals("+"))
result = n1+n2;
else if(operator.equals("-"))
result = n1-n2;
else if(operator.equals("*"))
result = n1*n2;
else
result = n1/n2;
%>
<body>
<form action="cal.jsp" method="post">
<h1>简易计算器</h1>
第一个操作数:<input type="text" name="num1" id="num1" value=<%=n1%> /><br>
第二个操作数:<input type="text" name="num2" id="num2" value=<%=n2%> /><br>
操作:<select name="operator">
<option value="+"<%if(operator.equals("+")) out.println("selected");%>>+</option>
<option value="-"<%if(operator.equals("-")) out.println("selected");%>>-</option>
<option value="*"<%if(operator.equals("*")) out.println("selected");%>>*</option>
<option value="/"<%if(operator.equals("/")) out.println("selected");%>>/</option>
</select>
<input type="submit" value="计算" name="button1"onclick="return check()" /><br>
计算结果:<%=result%>
</form>
</body>
</html>输入英文的时候没有出现警告,报错。想问大神怎么回事,找了好久也不知道哪里错了。

相关推荐
求所有的亲密数对!!!
求所有的亲密数对!!!
雷尼绍球杆仪数据怎么看 求助!!!
求助!!!测试的时候是让球杆仪逆时针转两圈,然后顺时针转两圈,得到的源文件如下为什么有这么多组数据,我该用哪一个啊??? 100 100 0 360 180 100 X Y CCW CW -0.1 0.1 -0.1 0.1 90 110 1 3.97887357729738 0 lcw 20200108-220206 20200108-222316 Renishaw QC20-W 064J33 1 064J33-130813-00 20130813 Renishaw Renishaw Ballbar 20 5.09.05.03 CCW 20.0 626 1876 3.984 -
简明英汉词典词库完全版!430万词条!!!最全词典整合收录!全网最多!俚语、短语、专业、新词全部收录!完美支持GoldenDict!一部在手,天下我有!
简明英汉词典词库完全版!430万词条!!!最全词典整合收录!全网最多!俚语、短语、专业、新词全部收录!完美支持GoldenDict!一部在手,天下我有!
什么是模式?什么是框架?为你详细解答,come on!!!
什么是模式?什么是框架?为你详细解答,come on!!!
php7 imagick安装包-win版(坑了好久好久,亲测可用)
因公司有很多用imagick制作的效果,总在线上调试特不方便。所以本地想安装imagick扩展。安了好久,期间放弃过好几次。 (win太坑了!~ 泪奔~~) ReadMe文件部分简介 ----- 安装php扩展 --- 解压 ****.zip 将php_imagick.dll 放到php的扩展目录如 f:/local/phpstudy/php7n/ext 配置php.ini 开启扩展 extension=php_imagick.dll --- 安装imagick软件 --- 解压 ****.zip 到要安装的目录如 c:/imagick 环境变量设置: path中 添加 c:/安装目录/bin 重启电脑 注: 此版本imagick仅支持php7.0



