javaweb设计简易购物车
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1" import="java.util.*"%>
<!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=ISO-8859-1">
<title>购物车数量小程序</title>
</head>
<body>
<script>
function add(){
var x=document.getElementById("a1")
var a=x.value
a++;
x.value=a;
}
function sub(){
var x=document.getElementById("a1")
var a=x.value
a--;
if(a<0)
{ x.value=0;}
else{ x.value=a; }
}
</script>
购买数量<input type="button" value="-" onclick="sub()" >
<input type="type" id=a1 value="0" size=1 >
<input type="button" value="+" onclick="add()" >
</body>
</html>
结果如图所示: