在实现购物网站时,往往会根据用户要求可以自定义的根据“+”和“-”选择商品数量,退出时返回登录界面。
点击“+”,数量不断增加;点击“-”,数量不断减少。
代码如下:
<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body bgcolor="#e3e3e3" >
<form action="" method="post"><center>
<table >
<caption >欢迎来到购物网站</caption>
<tr>
<td>商品1</td><td>购买数量:</td>
<td><input type="button" value="+" οnclick="this.form.c1.value++"/>
<input type="text" name="c1"value=0 size="4"/>
<input type="button" value="-" οnclick="this.form.c1.value--"/></td>
</tr>
<tr>
<td>商品2</td><td>购买数量:</td>
<td><input type="button" value="+" οnclick="this.form.c2.value++"/>
<input type="text" name="c2"value=0 size="4"/>
<input type="button" value="-" οnclick="this.form.c2.value--"/></td>
</tr>
<tr>
<td>商品3</td><td>购买数量:</td>
<td><input type="button" value="+" οnclick="this.form.c3.value++"/>
<input type="text" name="c3"value=0 size="4"/>
<input type="button" value="-" οnclick="this.form.c3.value--"/></td>
</tr>
</table>
<input type="submit" value="保存"/>
</center>
</form>
<input type="button" value="退出" οnclick="window.location.href='login.jsp'"/>
</body>
</html>
实现效果如下: