JSP简易加法

JSP简易加法,第1张

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<%

String a1 =""

String a2 = ""

long s = 0

a1 = request.getParameter("a1")

a2 = request.getParameter("a2")

String outs=""

if(a1!=null &&!a1.trim().equals("") &&a2!=null &&!a2.trim().equals("")){

try{

s = Long.parseLong(a1)+Long.parseLong(a2)

outs = String.valueOf(s)

}catch(Exception ex){

outs="您输入的不是有效数字!"

}

}

if(a1==null||a2==null) {

a1 =""

a2 = ""

}

%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>

<title>max</title>

<meta http-equiv="Content-Type" content="text/htmlcharset=gb2312" />

</head>

<body>

<form name="form1" action="" method="post">

<input type="text" name="a1" id="a1" value="<%=a1%>"/>+

<input type="text" name="a2" id="a2" value="<%=a2%>"/>=

<input type="text" name="s" id="s" value="<%=outs%>"/>

<input type="submit" name="submit1" value="计算"/>

</form>

</body>

</html>

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<%

String a1 =""

String a2 = ""

long s = 0

a1 = request.getParameter("a1")

a2 = request.getParameter("a2")

String outs=""

if(a1!=null &&!a1.trim().equals("") &&a2!=null &&!a2.trim().equals("")){

try{

s = Long.parseLong(a1)+Long.parseLong(a2)

outs = String.valueOf(s)

}catch(Exception ex){

outs="您输入的不是有效数字!"

}

}

if(a1==null||a2==null) {

a1 =""

a2 = ""

}

%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>

<title>max</title>

<meta http-equiv="Content-Type" content="text/htmlcharset=gb2312" />

</head>

<body>

<form name="form1" action="" method="post">

<input type="text" name="a1" id="a1" value="<%=a1%>"/>+

<input type="text" name="a2" id="a2" value="<%=a2%>"/>=

<input type="text" name="s" id="s" value="<%=outs%>"/>

<input type="submit" name="submit1" value="计算"/>

</form>

</body>

</html>

<script type="text/javascript">

    function fn(act){

        var val = document.getElementById("num").value

        if(act.equals('jia')){

            val = val-1

        }else{

            val = val+1

        }

    }

</script>

<table>

<tr>

<td><input type="text" id="num" value="<%=i%>"/><td>

</tr>

<tr>

<td>

<input type="button" id="btn1" value="+" onclick="fn(jia)"/>&nbsp<input type="button" id="btn2" value="-" onclick="fn(jian)"/>

</td>

</tr>

</table>


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/11826556.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-19
下一篇 2023-05-19

发表评论

登录后才能评论

评论列表(0条)

保存