<%@ 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 'cart1.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">
<script type="text/javascript">
function jian() {
alert(" ---");
}
function addd() {
alert(" ++=");
}
</script>
</head>
<body>
<form method="post" >
<table border=1 align="center">
<tr>
<td colspan="4" align="center">訂單</td>
</tr>
<tr>
<td>商品</td>
<td>數量</td>
<td>總價</td>
</tr>
<tr>
<td>aaa</td>
<td><input type="button" name="jian" onClick="jian()" value="-"></button>
<input name="shuru" class="input_text" type="text" value="1" size="3">
<button name="addd" onClick="addd()">+</button></td>
<td><input name="cost" class="input_text" type="text" value="0" size="3"
value="0"></td>
</tr>
<tr>
<td colspan="4" align="center">
<button id="buy_anniu" type="submit" onClick="but()">提交</button>
<button type="reset">重置</button>
</td>
</tr>
</table>
</form>
</body>
</html>
不要用button標簽,用input type='button',你用button標簽再標准浏覽器下是提交按鈕,直接提交表單了,而且你的輸入控件對象不要將name和你的函數名起一樣,會導致在onclick引用到這個控件,而不是你的函數
<tr>
<td>aaa</td>
<td><input type="button" onClick="jian()" value="-">
<input name="shuru" class="input_text" type="text" value="1" size="3">
<input type="button" onClick="addd()" value="+"/></td>
<td><input name="cost" class="input_text" type="text" value="0" size="3"
value="0"></td>
</tr>